Move components\profile_service to services\user
R=erg@chromium.org BUG= Review URL: https://codereview.chromium.org/1879233002 Cr-Commit-Position: refs/heads/master@{#387125}
This commit is contained in:
components/profile_service
content
services/user
@ -1,127 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/profile_service/profile_app.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "components/filesystem/lock_table.h"
|
||||
#include "components/leveldb/leveldb_service_impl.h"
|
||||
#include "components/profile_service/profile_service_impl.h"
|
||||
#include "components/profile_service/user_id_map.h"
|
||||
#include "mojo/public/cpp/bindings/callback.h"
|
||||
#include "services/shell/public/cpp/connection.h"
|
||||
|
||||
namespace profile {
|
||||
|
||||
class ProfileApp::ProfileServiceObjects
|
||||
: public base::SupportsWeakPtr<ProfileServiceObjects> {
|
||||
public:
|
||||
// Created on the main thread.
|
||||
ProfileServiceObjects(base::FilePath profile_data_dir)
|
||||
: profile_data_dir_(profile_data_dir) {}
|
||||
|
||||
// Destroyed on the |profile_service_runner_|.
|
||||
~ProfileServiceObjects() {}
|
||||
|
||||
// Called on the |profile_service_runner_|.
|
||||
void OnProfileServiceRequest(mojo::Connection* connection,
|
||||
ProfileServiceRequest request) {
|
||||
if (!lock_table_)
|
||||
lock_table_ = new filesystem::LockTable;
|
||||
profile_service_bindings_.AddBinding(
|
||||
new ProfileServiceImpl(profile_data_dir_, lock_table_),
|
||||
std::move(request));
|
||||
}
|
||||
|
||||
private:
|
||||
mojo::BindingSet<ProfileService> profile_service_bindings_;
|
||||
scoped_refptr<filesystem::LockTable> lock_table_;
|
||||
base::FilePath profile_data_dir_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProfileServiceObjects);
|
||||
};
|
||||
|
||||
class ProfileApp::LevelDBServiceObjects
|
||||
: public base::SupportsWeakPtr<LevelDBServiceObjects> {
|
||||
public:
|
||||
// Created on the main thread.
|
||||
LevelDBServiceObjects(scoped_refptr<base::SingleThreadTaskRunner> task_runner)
|
||||
: task_runner_(std::move(task_runner)) {}
|
||||
|
||||
// Destroyed on the |leveldb_service_runner_|.
|
||||
~LevelDBServiceObjects() {}
|
||||
|
||||
// Called on the |leveldb_service_runner_|.
|
||||
void OnLevelDBServiceRequest(mojo::Connection* connection,
|
||||
leveldb::LevelDBServiceRequest request) {
|
||||
if (!leveldb_service_)
|
||||
leveldb_service_.reset(new leveldb::LevelDBServiceImpl(task_runner_));
|
||||
leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request));
|
||||
}
|
||||
|
||||
private:
|
||||
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
||||
|
||||
// Variables that are only accessible on the |leveldb_service_runner_| thread.
|
||||
scoped_ptr<leveldb::LevelDBService> leveldb_service_;
|
||||
mojo::BindingSet<leveldb::LevelDBService> leveldb_bindings_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LevelDBServiceObjects);
|
||||
};
|
||||
|
||||
scoped_ptr<mojo::ShellClient> CreateProfileApp(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) {
|
||||
return make_scoped_ptr(new ProfileApp(
|
||||
std::move(profile_service_runner),
|
||||
std::move(leveldb_service_runner)));
|
||||
}
|
||||
|
||||
ProfileApp::ProfileApp(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner)
|
||||
: profile_service_runner_(std::move(profile_service_runner)),
|
||||
leveldb_service_runner_(std::move(leveldb_service_runner)) {}
|
||||
|
||||
ProfileApp::~ProfileApp() {
|
||||
profile_service_runner_->DeleteSoon(FROM_HERE, profile_objects_.release());
|
||||
leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release());
|
||||
}
|
||||
|
||||
void ProfileApp::Initialize(mojo::Connector* connector,
|
||||
const mojo::Identity& identity,
|
||||
uint32_t id) {
|
||||
tracing_.Initialize(connector, identity.name());
|
||||
profile_objects_.reset(new ProfileApp::ProfileServiceObjects(
|
||||
GetProfileDirForUserID(identity.user_id())));
|
||||
leveldb_objects_.reset(
|
||||
new ProfileApp::LevelDBServiceObjects(leveldb_service_runner_));
|
||||
}
|
||||
|
||||
bool ProfileApp::AcceptConnection(mojo::Connection* connection) {
|
||||
connection->AddInterface<leveldb::LevelDBService>(this);
|
||||
connection->AddInterface<ProfileService>(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProfileApp::Create(mojo::Connection* connection,
|
||||
ProfileServiceRequest request) {
|
||||
profile_service_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&ProfileApp::ProfileServiceObjects::OnProfileServiceRequest,
|
||||
profile_objects_->AsWeakPtr(), connection,
|
||||
base::Passed(&request)));
|
||||
}
|
||||
|
||||
void ProfileApp::Create(mojo::Connection* connection,
|
||||
leveldb::LevelDBServiceRequest request) {
|
||||
leveldb_service_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&ProfileApp::LevelDBServiceObjects::OnLevelDBServiceRequest,
|
||||
leveldb_objects_->AsWeakPtr(), connection,
|
||||
base::Passed(&request)));
|
||||
}
|
||||
|
||||
} // namespace profile
|
@ -1,14 +0,0 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_PROFILE_SERVICE_PUBLIC_CPP_CONSTANTS_H_
|
||||
#define COMPONENTS_PROFILE_SERVICE_PUBLIC_CPP_CONSTANTS_H_
|
||||
|
||||
namespace profile {
|
||||
|
||||
extern const char kProfileMojoApplicationName[];
|
||||
|
||||
} // namespace profile
|
||||
|
||||
#endif // COMPONENTS_PROFILE_SERVICE_PUBLIC_CPP_CONSTANTS_H_
|
@ -35,8 +35,6 @@ source_set("browser") {
|
||||
"//components/filesystem:lib",
|
||||
"//components/leveldb:lib",
|
||||
"//components/mime_util",
|
||||
"//components/profile_service:lib",
|
||||
"//components/profile_service/public/cpp",
|
||||
"//components/scheduler:common",
|
||||
"//components/tracing",
|
||||
"//components/tracing:startup_tracing",
|
||||
@ -77,6 +75,8 @@ source_set("browser") {
|
||||
"//services/shell/public/interfaces",
|
||||
"//services/shell/runner/common",
|
||||
"//services/shell/runner/host:lib",
|
||||
"//services/user:lib",
|
||||
"//services/user/public/cpp",
|
||||
"//skia",
|
||||
"//skia/public",
|
||||
"//sql",
|
||||
|
@ -18,9 +18,6 @@
|
||||
#include "base/macros.h"
|
||||
#include "base/rand_util.h"
|
||||
#include "build/build_config.h"
|
||||
#include "components/profile_service/profile_app.h"
|
||||
#include "components/profile_service/public/cpp/constants.h"
|
||||
#include "components/profile_service/user_id_map.h"
|
||||
#include "content/browser/download/download_manager_impl.h"
|
||||
#include "content/browser/fileapi/chrome_blob_storage_context.h"
|
||||
#include "content/browser/indexed_db/indexed_db_context_impl.h"
|
||||
@ -44,6 +41,9 @@
|
||||
#include "services/shell/public/cpp/connection.h"
|
||||
#include "services/shell/public/cpp/connector.h"
|
||||
#include "services/shell/public/interfaces/shell_client.mojom.h"
|
||||
#include "services/user/public/cpp/constants.h"
|
||||
#include "services/user/user_id_map.h"
|
||||
#include "services/user/user_shell_client.h"
|
||||
#include "storage/browser/database/database_tracker.h"
|
||||
#include "storage/browser/fileapi/external_mount_points.h"
|
||||
|
||||
@ -374,7 +374,7 @@ void BrowserContext::Initialize(
|
||||
g_used_user_ids.Get().insert(new_id);
|
||||
g_context_to_user_id.Get().push_back(std::make_pair(browser_context, new_id));
|
||||
|
||||
profile::AssociateMojoUserIDWithProfileDir(new_id, path);
|
||||
user_service::AssociateMojoUserIDWithUserDir(new_id, path);
|
||||
browser_context->SetUserData(kMojoWasInitialized,
|
||||
new base::SupportsUserData::Data);
|
||||
|
||||
@ -407,9 +407,9 @@ void BrowserContext::Initialize(
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kMojoLocalStorage)) {
|
||||
connection->AddEmbeddedApplication(
|
||||
profile::kProfileMojoApplicationName,
|
||||
user_service::kUserServiceName,
|
||||
base::Bind(
|
||||
&profile::CreateProfileApp,
|
||||
&user_service::CreateUserShellClient,
|
||||
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
|
||||
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)),
|
||||
nullptr);
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "base/thread_task_runner_handle.h"
|
||||
#include "components/filesystem/public/interfaces/directory.mojom.h"
|
||||
#include "components/leveldb/public/interfaces/leveldb.mojom.h"
|
||||
#include "components/profile_service/public/cpp/constants.h"
|
||||
#include "components/profile_service/public/interfaces/profile.mojom.h"
|
||||
#include "content/browser/dom_storage/dom_storage_area.h"
|
||||
#include "content/browser/dom_storage/dom_storage_context_impl.h"
|
||||
#include "content/browser/dom_storage/dom_storage_task_runner.h"
|
||||
@ -31,6 +29,8 @@
|
||||
#include "mojo/common/common_type_converters.h"
|
||||
#include "services/shell/public/cpp/connection.h"
|
||||
#include "services/shell/public/cpp/connector.h"
|
||||
#include "services/user/public/cpp/constants.h"
|
||||
#include "services/user/public/interfaces/user_service.mojom.h"
|
||||
|
||||
namespace content {
|
||||
namespace {
|
||||
@ -118,9 +118,9 @@ class DOMStorageContextWrapper::MojoState {
|
||||
CONNECTION_FINISHED
|
||||
} connection_state_;
|
||||
|
||||
std::unique_ptr<mojo::Connection> profile_app_connection_;
|
||||
std::unique_ptr<mojo::Connection> user_service_connection_;
|
||||
|
||||
profile::ProfileServicePtr profile_service_;
|
||||
user_service::mojom::UserServicePtr user_service_;
|
||||
filesystem::DirectoryPtr directory_;
|
||||
|
||||
leveldb::LevelDBServicePtr leveldb_service_;
|
||||
@ -138,22 +138,22 @@ void DOMStorageContextWrapper::MojoState::OpenLocalStorage(
|
||||
// If we don't have a filesystem_connection_, we'll need to establish one.
|
||||
if (connection_state_ == NO_CONNECTION) {
|
||||
CHECK(connector_);
|
||||
profile_app_connection_ =
|
||||
connector_->Connect(profile::kProfileMojoApplicationName);
|
||||
user_service_connection_ =
|
||||
connector_->Connect(user_service::kUserServiceName);
|
||||
connection_state_ = CONNECTION_IN_PROGRESS;
|
||||
|
||||
if (!subdirectory_.empty()) {
|
||||
// We were given a subdirectory to write to. Get it and use a disk backed
|
||||
// database.
|
||||
profile_app_connection_->GetInterface(&profile_service_);
|
||||
profile_service_->GetSubDirectory(
|
||||
user_service_connection_->GetInterface(&user_service_);
|
||||
user_service_->GetSubDirectory(
|
||||
mojo::String::From(subdirectory_.AsUTF8Unsafe()),
|
||||
GetProxy(&directory_),
|
||||
base::Bind(&MojoState::OnDirectoryOpened,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
} else {
|
||||
// We were not given a subdirectory. Use a memory backed database.
|
||||
profile_app_connection_->GetInterface(&leveldb_service_);
|
||||
user_service_connection_->GetInterface(&leveldb_service_);
|
||||
leveldb_service_->OpenInMemory(
|
||||
GetProxy(&database_),
|
||||
base::Bind(&MojoState::OnDatabaseOpened,
|
||||
@ -183,7 +183,7 @@ void DOMStorageContextWrapper::MojoState::OnDirectoryOpened(
|
||||
|
||||
// Now that we have a directory, connect to the LevelDB service and get our
|
||||
// database.
|
||||
profile_app_connection_->GetInterface(&leveldb_service_);
|
||||
user_service_connection_->GetInterface(&leveldb_service_);
|
||||
|
||||
leveldb_service_->Open(
|
||||
std::move(directory_), "leveldb", GetProxy(&database_),
|
||||
@ -199,11 +199,11 @@ void DOMStorageContextWrapper::MojoState::OnDatabaseOpened(
|
||||
leveldb_service_.reset();
|
||||
}
|
||||
|
||||
// We no longer need the profile service; we've either transferred
|
||||
// We no longer need the user service; we've either transferred
|
||||
// |directory_| to the leveldb service, or we got a file error and no more is
|
||||
// possible.
|
||||
directory_.reset();
|
||||
profile_service_.reset();
|
||||
user_service_.reset();
|
||||
|
||||
// |leveldb_| should be known to either be valid or invalid by now. Run our
|
||||
// delayed bindings.
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "base/path_service.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/thread_task_runner_handle.h"
|
||||
#include "components/profile_service/public/cpp/constants.h"
|
||||
#include "content/browser/gpu/gpu_process_host.h"
|
||||
#include "content/browser/mojo/constants.h"
|
||||
#include "content/common/gpu_process_launch_causes.h"
|
||||
@ -42,6 +41,7 @@
|
||||
#include "services/shell/public/cpp/shell_client.h"
|
||||
#include "services/shell/public/interfaces/connector.mojom.h"
|
||||
#include "services/shell/runner/host/in_process_native_runner.h"
|
||||
#include "services/user/public/cpp/constants.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
@ -241,7 +241,7 @@ MojoShellContext::MojoShellContext() {
|
||||
IDR_MOJO_CONTENT_RENDERER_MANIFEST);
|
||||
manifest_provider_->AddManifestResource("mojo:catalog",
|
||||
IDR_MOJO_CATALOG_MANIFEST);
|
||||
manifest_provider_->AddManifestResource(profile::kProfileMojoApplicationName,
|
||||
manifest_provider_->AddManifestResource(user_service::kUserServiceName,
|
||||
IDR_MOJO_PROFILE_MANIFEST);
|
||||
|
||||
catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr,
|
||||
|
@ -9,8 +9,6 @@
|
||||
'../cc/cc.gyp:cc_surfaces',
|
||||
'../components/leveldb/leveldb.gyp:leveldb_lib',
|
||||
'../components/mime_util/mime_util.gyp:mime_util',
|
||||
'../components/profile_service/profile_service.gyp:profile_service_lib',
|
||||
'../components/profile_service/profile_service.gyp:profile_service_public_lib',
|
||||
'../components/scheduler/scheduler.gyp:scheduler_common',
|
||||
'../components/url_formatter/url_formatter.gyp:url_formatter',
|
||||
'../crypto/crypto.gyp:crypto',
|
||||
@ -39,6 +37,8 @@
|
||||
'../services/shell/shell.gyp:shell_runner_host_lib',
|
||||
'../services/tracing/tracing.gyp:tracing_lib',
|
||||
'../services/tracing/tracing.gyp:tracing_public',
|
||||
'../services/user/user.gyp:user_service_lib',
|
||||
'../services/user/user.gyp:user_service_public_lib',
|
||||
'../skia/skia.gyp:skia',
|
||||
'../skia/skia.gyp:skia_mojo',
|
||||
'../sql/sql.gyp:sql',
|
||||
|
@ -30,7 +30,7 @@
|
||||
<include name="IDR_MOJO_CATALOG_MANIFEST" file="../services/catalog/manifest.json" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CONTENT_BROWSER_MANIFEST" file="${root_out_dir}/content_browser_manifest.json" use_base_dir="false" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CONTENT_RENDERER_MANIFEST" file="${root_out_dir}/content_renderer_manifest.json" use_base_dir="false" type="BINDATA" />
|
||||
<include name="IDR_MOJO_PROFILE_MANIFEST" file="../components/profile_service/manifest.json" type="BINDATA" />
|
||||
<include name="IDR_MOJO_PROFILE_MANIFEST" file="../services/user/manifest.json" type="BINDATA" />
|
||||
<include name="IDR_NETWORK_ERROR_LISTING_HTML" file="browser/resources/net/network_errors_listing.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
|
||||
<include name="IDR_NETWORK_ERROR_LISTING_JS" file="browser/resources/net/network_errors_listing.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_NETWORK_ERROR_LISTING_CSS" file="browser/resources/net/network_errors_listing.css" flattenhtml="true" type="BINDATA" />
|
||||
|
@ -146,9 +146,9 @@ mojo_application_manifest("browser_manifest") {
|
||||
type = "exe"
|
||||
application_name = "content_browser"
|
||||
source = "mojo/content_browser_manifest.json"
|
||||
packaged_applications = [ "profile" ]
|
||||
packaged_applications = [ "user" ]
|
||||
deps = [
|
||||
"//components/profile_service:manifest",
|
||||
"//services/user:manifest",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,12 @@ import("//mojo/public/mojo_application_manifest.gni")
|
||||
|
||||
source_set("lib") {
|
||||
sources = [
|
||||
"profile_app.cc",
|
||||
"profile_app.h",
|
||||
"profile_service_impl.cc",
|
||||
"profile_service_impl.h",
|
||||
"user_id_map.cc",
|
||||
"user_id_map.h",
|
||||
"user_service.cc",
|
||||
"user_service.h",
|
||||
"user_shell_client.cc",
|
||||
"user_shell_client.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
@ -21,7 +21,6 @@ source_set("lib") {
|
||||
"//components/filesystem/public/interfaces",
|
||||
"//components/leveldb:lib",
|
||||
"//components/leveldb/public/interfaces",
|
||||
"//components/profile_service/public/interfaces",
|
||||
"//mojo/common",
|
||||
"//mojo/common:common_base",
|
||||
"//mojo/message_pump",
|
||||
@ -29,6 +28,7 @@ source_set("lib") {
|
||||
"//services/shell/public/cpp",
|
||||
"//services/shell/public/interfaces",
|
||||
"//services/tracing/public/cpp",
|
||||
"//services/user/public/interfaces",
|
||||
"//url",
|
||||
]
|
||||
|
||||
@ -38,6 +38,6 @@ source_set("lib") {
|
||||
}
|
||||
|
||||
mojo_application_manifest("manifest") {
|
||||
application_name = "profile"
|
||||
application_name = "user"
|
||||
source = "manifest.json"
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "mojo:profile",
|
||||
"name": "mojo:user",
|
||||
"process-group": "browser",
|
||||
"display_name": "Profile",
|
||||
"display_name": "User Service",
|
||||
"capabilities": {
|
||||
"required": {
|
||||
"mojo:tracing": { "interfaces": [ "*" ] }
|
@ -2,10 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/profile_service/public/cpp/constants.h"
|
||||
#include "services/user/public/cpp/constants.h"
|
||||
|
||||
namespace profile {
|
||||
namespace user_service {
|
||||
|
||||
const char kProfileMojoApplicationName[] = "mojo:profile";
|
||||
const char kUserServiceName[] = "mojo:user";
|
||||
|
||||
} // namespace profile
|
||||
} // namespace user_service
|
14
services/user/public/cpp/constants.h
Normal file
14
services/user/public/cpp/constants.h
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SERVICES_USER_PUBLIC_CPP_CONSTANTS_H_
|
||||
#define SERVICES_USER_PUBLIC_CPP_CONSTANTS_H_
|
||||
|
||||
namespace user_service {
|
||||
|
||||
extern const char kUserServiceName[];
|
||||
|
||||
} // namespace user_service
|
||||
|
||||
#endif // SERVICES_USER_PUBLIC_CPP_CONSTANTS_H_
|
@ -6,7 +6,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
|
||||
|
||||
mojom("interfaces") {
|
||||
sources = [
|
||||
"profile.mojom",
|
||||
"user_service.mojom",
|
||||
]
|
||||
|
||||
deps = [
|
@ -2,17 +2,17 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
module profile;
|
||||
module user_service.mojom;
|
||||
|
||||
import "components/filesystem/public/interfaces/directory.mojom";
|
||||
import "components/filesystem/public/interfaces/types.mojom";
|
||||
|
||||
// An encapsulation around the per-profile storage.
|
||||
//
|
||||
// TODO(erg): A Profile should be strongly bound to a User; eventually, during
|
||||
// startup of the Profile process, we sandbox the process so the only directory
|
||||
// it has access to is the User's profile.
|
||||
interface ProfileService {
|
||||
// TODO(erg): An instance of UserService should be strongly bound to a specific
|
||||
// user id; eventually during startup of the User Service process, we sandbox
|
||||
// the process so the only directory it has access to is the user's directory.
|
||||
interface UserService {
|
||||
// Returns the user profile directory.
|
||||
GetDirectory(filesystem.Directory& dir) => ();
|
||||
|
@ -11,23 +11,23 @@
|
||||
},
|
||||
'targets': [
|
||||
{
|
||||
# GN version: //components/profile_serivce:lib
|
||||
'target_name': 'profile_service_lib',
|
||||
# GN version: //services/user:lib
|
||||
'target_name': 'user_service_lib',
|
||||
'type': 'static_library',
|
||||
'include_dirs': [
|
||||
'../..',
|
||||
],
|
||||
'sources': [
|
||||
'profile_app.cc',
|
||||
'profile_app.h',
|
||||
'profile_service_impl.cc',
|
||||
'profile_service_impl.h',
|
||||
'user_id_map.cc',
|
||||
'user_id_map.h',
|
||||
'user_service.cc',
|
||||
'user_service.h',
|
||||
'user_shell_client.cc',
|
||||
'user_shell_client.h',
|
||||
],
|
||||
'dependencies': [
|
||||
'profile_app_manifest',
|
||||
'profile_service_bindings',
|
||||
'user_app_manifest',
|
||||
'user_service_bindings',
|
||||
'../../base/base.gyp:base',
|
||||
'../../components/filesystem/filesystem.gyp:filesystem_lib',
|
||||
'../../components/leveldb/leveldb.gyp:leveldb_lib',
|
||||
@ -39,23 +39,23 @@
|
||||
'../../url/url.gyp:url_lib',
|
||||
],
|
||||
'export_dependent_settings': [
|
||||
'profile_service_bindings',
|
||||
'user_service_bindings',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //components/profile_service/public/interfaces
|
||||
'target_name': 'profile_service_bindings',
|
||||
# GN version: //services/user/public/interfaces
|
||||
'target_name': 'user_service_bindings',
|
||||
'type': 'static_library',
|
||||
'dependencies': [
|
||||
'profile_service_bindings_mojom',
|
||||
'user_service_bindings_mojom',
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'profile_service_bindings_mojom',
|
||||
'target_name': 'user_service_bindings_mojom',
|
||||
'type': 'none',
|
||||
'variables': {
|
||||
'mojom_files': [
|
||||
'public/interfaces/profile.mojom',
|
||||
'public/interfaces/user_service.mojom',
|
||||
],
|
||||
},
|
||||
'dependencies': [
|
||||
@ -67,7 +67,7 @@
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'profile_service_public_lib',
|
||||
'target_name': 'user_service_public_lib',
|
||||
'type': 'static_library',
|
||||
'sources': [
|
||||
'public/cpp/constants.cc',
|
||||
@ -78,13 +78,13 @@
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //components/profile_service:manifest
|
||||
'target_name': 'profile_app_manifest',
|
||||
# GN version: //services/user:manifest
|
||||
'target_name': 'user_app_manifest',
|
||||
'type': 'none',
|
||||
'variables': {
|
||||
'application_type': 'mojo',
|
||||
'application_name': 'profile',
|
||||
'source_manifest': '<(DEPTH)/components/profile_service/manifest.json',
|
||||
'application_name': 'user',
|
||||
'source_manifest': '<(DEPTH)/services/user/manifest.json',
|
||||
},
|
||||
'includes': [
|
||||
'../../mojo/public/mojo_application_manifest.gypi',
|
@ -2,28 +2,28 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/profile_service/user_id_map.h"
|
||||
#include "services/user/user_id_map.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "base/lazy_instance.h"
|
||||
|
||||
namespace profile {
|
||||
namespace user_service {
|
||||
|
||||
namespace {
|
||||
base::LazyInstance<std::map<std::string, base::FilePath>>
|
||||
g_user_id_to_data_dir = LAZY_INSTANCE_INITIALIZER;
|
||||
} // namespace
|
||||
|
||||
void AssociateMojoUserIDWithProfileDir(const std::string& user_id,
|
||||
const base::FilePath& profile_data_dir) {
|
||||
g_user_id_to_data_dir.Get()[user_id] = profile_data_dir;
|
||||
void AssociateMojoUserIDWithUserDir(const std::string& user_id,
|
||||
const base::FilePath& user_dir) {
|
||||
g_user_id_to_data_dir.Get()[user_id] = user_dir;
|
||||
}
|
||||
|
||||
base::FilePath GetProfileDirForUserID(const std::string& user_id) {
|
||||
base::FilePath GetUserDirForUserID(const std::string& user_id) {
|
||||
auto it = g_user_id_to_data_dir.Get().find(user_id);
|
||||
DCHECK(it != g_user_id_to_data_dir.Get().end());
|
||||
return it->second;
|
||||
}
|
||||
|
||||
} // namespace profile
|
||||
} // namespace user_service
|
@ -2,30 +2,30 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_PROFILE_SERVICE_USER_ID_MAP_H_
|
||||
#define COMPONENTS_PROFILE_SERVICE_USER_ID_MAP_H_
|
||||
#ifndef SERVICES_USER_USER_ID_MAP_H_
|
||||
#define SERVICES_USER_USER_ID_MAP_H_
|
||||
|
||||
#include <string>
|
||||
#include "base/files/file_path.h"
|
||||
|
||||
namespace profile {
|
||||
namespace user_service {
|
||||
|
||||
// Currently, ProfileApp is run from within the chrome process. This means that
|
||||
// Currently, UserApp is run from within the chrome process. This means that
|
||||
// the ApplicationLoader is registered during MojoShellContext startup, even
|
||||
// though the application itself is not started. As soon as a BrowserContext is
|
||||
// created, the BrowserContext will choose a |user_id| for itself and call us
|
||||
// to register the mapping from |user_id| to |profile_data_dir|.
|
||||
// to register the mapping from |user_id| to |user_dir|.
|
||||
//
|
||||
// This data is then accessed when we get our Initialize() call.
|
||||
//
|
||||
// TODO(erg): This is a temporary hack until we redo how we initialize mojo
|
||||
// applications inside of chrome in general; this system won't work once
|
||||
// ProfileApp gets put in its own sandboxed process.
|
||||
void AssociateMojoUserIDWithProfileDir(const std::string& user_id,
|
||||
const base::FilePath& profile_data_dir);
|
||||
// UserApp gets put in its own sandboxed process.
|
||||
void AssociateMojoUserIDWithUserDir(const std::string& user_id,
|
||||
const base::FilePath& user_dir);
|
||||
|
||||
base::FilePath GetProfileDirForUserID(const std::string& user_id);
|
||||
base::FilePath GetUserDirForUserID(const std::string& user_id);
|
||||
|
||||
} // namespace profile
|
||||
} // namespace user_service
|
||||
|
||||
#endif // COMPONENTS_PROFILE_SERVICE_USER_ID_MAP_H_
|
||||
#endif // SERVICES_USER_USER_ID_MAP_H_
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/profile_service/profile_service_impl.h"
|
||||
#include "services/user/user_service.h"
|
||||
|
||||
#include "base/files/file.h"
|
||||
#include "base/files/file_path.h"
|
||||
@ -15,19 +15,18 @@
|
||||
#include "services/shell/public/cpp/connection.h"
|
||||
#include "services/shell/public/cpp/message_loop_ref.h"
|
||||
|
||||
namespace profile {
|
||||
namespace user_service {
|
||||
|
||||
ProfileServiceImpl::ProfileServiceImpl(
|
||||
const base::FilePath& base_profile_dir,
|
||||
const scoped_refptr<filesystem::LockTable>& lock_table)
|
||||
: lock_table_(lock_table), path_(base_profile_dir) {
|
||||
UserService::UserService(const base::FilePath& base_user_dir,
|
||||
const scoped_refptr<filesystem::LockTable>& lock_table)
|
||||
: lock_table_(lock_table), path_(base_user_dir) {
|
||||
base::CreateDirectory(path_);
|
||||
}
|
||||
|
||||
ProfileServiceImpl::~ProfileServiceImpl() {}
|
||||
UserService::~UserService() {}
|
||||
|
||||
void ProfileServiceImpl::GetDirectory(filesystem::DirectoryRequest request,
|
||||
const GetDirectoryCallback& callback) {
|
||||
void UserService::GetDirectory(filesystem::DirectoryRequest request,
|
||||
const GetDirectoryCallback& callback) {
|
||||
new filesystem::DirectoryImpl(std::move(request),
|
||||
path_,
|
||||
scoped_ptr<base::ScopedTempDir>(),
|
||||
@ -35,11 +34,10 @@ void ProfileServiceImpl::GetDirectory(filesystem::DirectoryRequest request,
|
||||
callback.Run();
|
||||
}
|
||||
|
||||
void ProfileServiceImpl::GetSubDirectory(
|
||||
const mojo::String& sub_directory_path,
|
||||
filesystem::DirectoryRequest request,
|
||||
const GetSubDirectoryCallback& callback) {
|
||||
// Ensure that we've made |subdirectory| recursively under our profile.
|
||||
void UserService::GetSubDirectory(const mojo::String& sub_directory_path,
|
||||
filesystem::DirectoryRequest request,
|
||||
const GetSubDirectoryCallback& callback) {
|
||||
// Ensure that we've made |subdirectory| recursively under our user dir.
|
||||
base::FilePath subdir = path_.Append(
|
||||
#if defined(OS_WIN)
|
||||
base::UTF8ToWide(sub_directory_path.To<std::string>()));
|
||||
@ -57,4 +55,4 @@ void ProfileServiceImpl::GetSubDirectory(
|
||||
callback.Run(filesystem::FileError::OK);
|
||||
}
|
||||
|
||||
} // namespace profile
|
||||
} // namespace user_service
|
@ -2,15 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_PROFILE_SERVICE_PROFILE_SERVICE_IMPL_H_
|
||||
#define COMPONENTS_PROFILE_SERVICE_PROFILE_SERVICE_IMPL_H_
|
||||
#ifndef SERVICES_USER_USER_SERVICE_IMPL_H_
|
||||
#define SERVICES_USER_USER_SERVICE_IMPL_H_
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "components/filesystem/public/interfaces/directory.mojom.h"
|
||||
#include "components/profile_service/public/interfaces/profile.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding.h"
|
||||
#include "services/shell/public/cpp/connection.h"
|
||||
#include "services/user/public/interfaces/user_service.mojom.h"
|
||||
|
||||
namespace filesystem {
|
||||
class LockTable;
|
||||
@ -20,16 +20,16 @@ namespace mojo {
|
||||
class MessageLoopRef;
|
||||
}
|
||||
|
||||
namespace profile {
|
||||
namespace user_service {
|
||||
|
||||
// A service which serves directories to callers.
|
||||
class ProfileServiceImpl : public ProfileService {
|
||||
class UserService : public mojom::UserService {
|
||||
public:
|
||||
ProfileServiceImpl(const base::FilePath& base_profile_dir,
|
||||
const scoped_refptr<filesystem::LockTable>& lock_table);
|
||||
~ProfileServiceImpl() override;
|
||||
UserService(const base::FilePath& base_user_dir,
|
||||
const scoped_refptr<filesystem::LockTable>& lock_table);
|
||||
~UserService() override;
|
||||
|
||||
// Overridden from ProfileService:
|
||||
// Overridden from mojom::UserService:
|
||||
void GetDirectory(filesystem::DirectoryRequest request,
|
||||
const GetDirectoryCallback& callback) override;
|
||||
void GetSubDirectory(const mojo::String& sub_directory_path,
|
||||
@ -40,9 +40,9 @@ class ProfileServiceImpl : public ProfileService {
|
||||
scoped_refptr<filesystem::LockTable> lock_table_;
|
||||
base::FilePath path_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProfileServiceImpl);
|
||||
DISALLOW_COPY_AND_ASSIGN(UserService);
|
||||
};
|
||||
|
||||
} // namespace profile
|
||||
} // namespace user_service
|
||||
|
||||
#endif // COMPONENTS_PROFILE_SERVICE_PROFILE_SERVICE_IMPL_H_
|
||||
#endif // SERVICES_USER_USER_SERVICE_IMPL_H_
|
125
services/user/user_shell_client.cc
Normal file
125
services/user/user_shell_client.cc
Normal file
@ -0,0 +1,125 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "services/user/user_shell_client.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "components/filesystem/lock_table.h"
|
||||
#include "components/leveldb/leveldb_service_impl.h"
|
||||
#include "mojo/public/cpp/bindings/callback.h"
|
||||
#include "services/shell/public/cpp/connection.h"
|
||||
#include "services/user/user_id_map.h"
|
||||
#include "services/user/user_service.h"
|
||||
|
||||
namespace user_service {
|
||||
|
||||
class UserShellClient::UserServiceObjects
|
||||
: public base::SupportsWeakPtr<UserServiceObjects> {
|
||||
public:
|
||||
// Created on the main thread.
|
||||
UserServiceObjects(base::FilePath user_dir) : user_dir_(user_dir) {}
|
||||
|
||||
// Destroyed on the |user_service_runner_|.
|
||||
~UserServiceObjects() {}
|
||||
|
||||
// Called on the |user_service_runner_|.
|
||||
void OnUserServiceRequest(mojo::Connection* connection,
|
||||
mojom::UserServiceRequest request) {
|
||||
if (!lock_table_)
|
||||
lock_table_ = new filesystem::LockTable;
|
||||
user_service_bindings_.AddBinding(new UserService(user_dir_, lock_table_),
|
||||
std::move(request));
|
||||
}
|
||||
|
||||
private:
|
||||
mojo::BindingSet<mojom::UserService> user_service_bindings_;
|
||||
scoped_refptr<filesystem::LockTable> lock_table_;
|
||||
base::FilePath user_dir_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(UserServiceObjects);
|
||||
};
|
||||
|
||||
class UserShellClient::LevelDBServiceObjects
|
||||
: public base::SupportsWeakPtr<LevelDBServiceObjects> {
|
||||
public:
|
||||
// Created on the main thread.
|
||||
LevelDBServiceObjects(scoped_refptr<base::SingleThreadTaskRunner> task_runner)
|
||||
: task_runner_(std::move(task_runner)) {}
|
||||
|
||||
// Destroyed on the |leveldb_service_runner_|.
|
||||
~LevelDBServiceObjects() {}
|
||||
|
||||
// Called on the |leveldb_service_runner_|.
|
||||
void OnLevelDBServiceRequest(mojo::Connection* connection,
|
||||
leveldb::LevelDBServiceRequest request) {
|
||||
if (!leveldb_service_)
|
||||
leveldb_service_.reset(new leveldb::LevelDBServiceImpl(task_runner_));
|
||||
leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request));
|
||||
}
|
||||
|
||||
private:
|
||||
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
||||
|
||||
// Variables that are only accessible on the |leveldb_service_runner_| thread.
|
||||
scoped_ptr<leveldb::LevelDBService> leveldb_service_;
|
||||
mojo::BindingSet<leveldb::LevelDBService> leveldb_bindings_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LevelDBServiceObjects);
|
||||
};
|
||||
|
||||
scoped_ptr<mojo::ShellClient> CreateUserShellClient(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_service_runner,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) {
|
||||
return make_scoped_ptr(new UserShellClient(std::move(user_service_runner),
|
||||
std::move(leveldb_service_runner)));
|
||||
}
|
||||
|
||||
UserShellClient::UserShellClient(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_service_runner,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner)
|
||||
: user_service_runner_(std::move(user_service_runner)),
|
||||
leveldb_service_runner_(std::move(leveldb_service_runner)) {}
|
||||
|
||||
UserShellClient::~UserShellClient() {
|
||||
user_service_runner_->DeleteSoon(FROM_HERE, user_objects_.release());
|
||||
leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release());
|
||||
}
|
||||
|
||||
void UserShellClient::Initialize(mojo::Connector* connector,
|
||||
const mojo::Identity& identity,
|
||||
uint32_t id) {
|
||||
tracing_.Initialize(connector, identity.name());
|
||||
user_objects_.reset(new UserShellClient::UserServiceObjects(
|
||||
GetUserDirForUserID(identity.user_id())));
|
||||
leveldb_objects_.reset(
|
||||
new UserShellClient::LevelDBServiceObjects(leveldb_service_runner_));
|
||||
}
|
||||
|
||||
bool UserShellClient::AcceptConnection(mojo::Connection* connection) {
|
||||
connection->AddInterface<leveldb::LevelDBService>(this);
|
||||
connection->AddInterface<mojom::UserService>(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UserShellClient::Create(mojo::Connection* connection,
|
||||
mojom::UserServiceRequest request) {
|
||||
user_service_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&UserShellClient::UserServiceObjects::OnUserServiceRequest,
|
||||
user_objects_->AsWeakPtr(), connection,
|
||||
base::Passed(&request)));
|
||||
}
|
||||
|
||||
void UserShellClient::Create(mojo::Connection* connection,
|
||||
leveldb::LevelDBServiceRequest request) {
|
||||
leveldb_service_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(
|
||||
&UserShellClient::LevelDBServiceObjects::OnLevelDBServiceRequest,
|
||||
leveldb_objects_->AsWeakPtr(), connection,
|
||||
base::Passed(&request)));
|
||||
}
|
||||
|
||||
} // namespace user_service
|
@ -2,39 +2,32 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_PROFILE_SERVICE_PROFILE_APP_H_
|
||||
#define COMPONENTS_PROFILE_SERVICE_PROFILE_APP_H_
|
||||
#ifndef SERVICES_USER_USER_SHELL_CLIENT_H_
|
||||
#define SERVICES_USER_USER_SHELL_CLIENT_H_
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "components/filesystem/lock_table.h"
|
||||
#include "components/leveldb/public/interfaces/leveldb.mojom.h"
|
||||
#include "components/profile_service/public/interfaces/profile.mojom.h"
|
||||
#include "mojo/public/cpp/bindings/binding_set.h"
|
||||
#include "services/shell/public/cpp/interface_factory.h"
|
||||
#include "services/shell/public/cpp/shell_client.h"
|
||||
#include "services/tracing/public/cpp/tracing_impl.h"
|
||||
#include "services/user/public/interfaces/user_service.mojom.h"
|
||||
|
||||
namespace profile {
|
||||
namespace user_service {
|
||||
|
||||
scoped_ptr<mojo::ShellClient> CreateProfileApp(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner,
|
||||
scoped_ptr<mojo::ShellClient> CreateUserShellClient(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_service_runner,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner);
|
||||
|
||||
// Application which hands off per-profile services.
|
||||
//
|
||||
// This Application serves ProfileService. In the future, this application will
|
||||
// probably also offer any service that most Profile using applications will
|
||||
// need, such as preferences; this class will have to be made into a
|
||||
// application which is an InterfaceProvider which internally spawns threads
|
||||
// for different sub-applications.
|
||||
class ProfileApp : public mojo::ShellClient,
|
||||
public mojo::InterfaceFactory<ProfileService>,
|
||||
public mojo::InterfaceFactory<leveldb::LevelDBService> {
|
||||
class UserShellClient : public mojo::ShellClient,
|
||||
public mojo::InterfaceFactory<mojom::UserService>,
|
||||
public mojo::InterfaceFactory<leveldb::LevelDBService> {
|
||||
public:
|
||||
ProfileApp(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner,
|
||||
UserShellClient(
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_service_runner,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner);
|
||||
~ProfileApp() override;
|
||||
~UserShellClient() override;
|
||||
|
||||
private:
|
||||
// |ShellClient| override:
|
||||
@ -43,9 +36,9 @@ class ProfileApp : public mojo::ShellClient,
|
||||
uint32_t id) override;
|
||||
bool AcceptConnection(mojo::Connection* connection) override;
|
||||
|
||||
// |InterfaceFactory<ProfileService>| implementation:
|
||||
// |InterfaceFactory<mojom::UserService>| implementation:
|
||||
void Create(mojo::Connection* connection,
|
||||
ProfileServiceRequest request) override;
|
||||
mojom::UserServiceRequest request) override;
|
||||
|
||||
// |InterfaceFactory<LevelDBService>| implementation:
|
||||
void Create(mojo::Connection* connection,
|
||||
@ -55,22 +48,22 @@ class ProfileApp : public mojo::ShellClient,
|
||||
leveldb::LevelDBServiceRequest request);
|
||||
void OnLevelDBServiceError();
|
||||
|
||||
scoped_refptr<base::SingleThreadTaskRunner> profile_service_runner_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> user_service_runner_;
|
||||
scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner_;
|
||||
|
||||
mojo::TracingImpl tracing_;
|
||||
|
||||
// We create these two objects so we can delete them on the correct task
|
||||
// runners.
|
||||
class ProfileServiceObjects;
|
||||
scoped_ptr<ProfileServiceObjects> profile_objects_;
|
||||
class UserServiceObjects;
|
||||
scoped_ptr<UserServiceObjects> user_objects_;
|
||||
|
||||
class LevelDBServiceObjects;
|
||||
scoped_ptr<LevelDBServiceObjects> leveldb_objects_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProfileApp);
|
||||
DISALLOW_COPY_AND_ASSIGN(UserShellClient);
|
||||
};
|
||||
|
||||
} // namespace profile
|
||||
} // namespace user_service
|
||||
|
||||
#endif // COMPONENTS_PROFILE_SERVICE_PROFILE_APP_H_
|
||||
#endif // SERVICES_USER_USER_SHELL_CLIENT_H_
|
Reference in New Issue
Block a user