Commit c4ba1060 authored by jonross's avatar jonross Committed by Commit bot

Have ActiveProfilePrefService Use the Original Profile

ActiveProfilePrefService attempts to bind connections to the active profile.
However Incognito profiles do not register with the preference service. This
was leading to ServiceManagerConnectionImpl rejecting the connection, as there
was no registered service.

This change switches to using the original profile for the connection. Incognito
profile is backed by a base ProfileImpl. All ProfileImpl properly register as a
service.

This change also reenables the ash::shell connection to the pref service.

This change also reverts https://codereview.chromium.org/2795413002 which was
landed to deal with possible race condition of request handlers. However this
was not the root cause.

TESTING=device actually boots now, ash::shell receives its connection to prefs.
User can login.
BUG=707321

Review-Url: https://codereview.chromium.org/2802093005
Cr-Commit-Position: refs/heads/master@{#462997}
parent d7e1c1db
...@@ -791,8 +791,6 @@ void Shell::Init(const ShellInitParams& init_params) { ...@@ -791,8 +791,6 @@ void Shell::Init(const ShellInitParams& init_params) {
wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate(); wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate();
// Can be null in tests. // Can be null in tests.
// TODO(jonross): reenable once the cause of crbug.com/707321 is determined.
/*
if (wm_shell_->IsRunningInMash() && shell_delegate_->GetShellConnector()) { if (wm_shell_->IsRunningInMash() && shell_delegate_->GetShellConnector()) {
prefs::ConnectToPrefService( prefs::ConnectToPrefService(
shell_delegate_->GetShellConnector(), shell_delegate_->GetShellConnector(),
...@@ -800,7 +798,7 @@ void Shell::Init(const ShellInitParams& init_params) { ...@@ -800,7 +798,7 @@ void Shell::Init(const ShellInitParams& init_params) {
std::vector<PrefValueStore::PrefStoreType>(), std::vector<PrefValueStore::PrefStoreType>(),
base::Bind(&Shell::OnPrefServiceInitialized, base::Unretained(this)), base::Bind(&Shell::OnPrefServiceInitialized, base::Unretained(this)),
prefs::mojom::kForwarderServiceName); prefs::mojom::kForwarderServiceName);
}*/ }
// Some delegates access WmShell during their construction. Create them here // Some delegates access WmShell during their construction. Create them here
// instead of the WmShell constructor. // instead of the WmShell constructor.
......
...@@ -19,7 +19,7 @@ void ActiveProfilePrefService::Connect( ...@@ -19,7 +19,7 @@ void ActiveProfilePrefService::Connect(
const std::vector<PrefValueStore::PrefStoreType>& already_connected_types, const std::vector<PrefValueStore::PrefStoreType>& already_connected_types,
const ConnectCallback& callback) { const ConnectCallback& callback) {
auto* connector = content::BrowserContext::GetConnectorFor( auto* connector = content::BrowserContext::GetConnectorFor(
ProfileManager::GetActiveUserProfile()); ProfileManager::GetActiveUserProfile()->GetOriginalProfile());
connector->BindInterface(prefs::mojom::kServiceName, &connector_ptr_); connector->BindInterface(prefs::mojom::kServiceName, &connector_ptr_);
connector_ptr_.set_connection_error_handler(base::Bind( connector_ptr_.set_connection_error_handler(base::Bind(
&ActiveProfilePrefService::OnConnectError, base::Unretained(this))); &ActiveProfilePrefService::OnConnectError, base::Unretained(this)));
......
...@@ -139,11 +139,6 @@ class ServiceManagerConnectionImpl::IOThreadContext ...@@ -139,11 +139,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
private: private:
friend class base::RefCountedThreadSafe<IOThreadContext>; friend class base::RefCountedThreadSafe<IOThreadContext>;
struct PendingRequest {
std::string service_name;
service_manager::mojom::ServiceRequest request;
};
class MessageLoopObserver : public base::MessageLoop::DestructionObserver { class MessageLoopObserver : public base::MessageLoop::DestructionObserver {
public: public:
explicit MessageLoopObserver(base::WeakPtr<IOThreadContext> context) explicit MessageLoopObserver(base::WeakPtr<IOThreadContext> context)
...@@ -261,16 +256,6 @@ class ServiceManagerConnectionImpl::IOThreadContext ...@@ -261,16 +256,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK(io_thread_checker_.CalledOnValidThread());
auto result = request_handlers_.insert(std::make_pair(name, handler)); auto result = request_handlers_.insert(std::make_pair(name, handler));
DCHECK(result.second); DCHECK(result.second);
auto iter = pending_requests_.begin();
while (iter != pending_requests_.end()) {
if ((*iter)->service_name == name) {
std::unique_ptr<PendingRequest> pending_request = std::move(*iter);
iter = pending_requests_.erase(iter);
handler.Run(std::move(pending_request->request));
} else {
++iter;
}
}
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -344,14 +329,8 @@ class ServiceManagerConnectionImpl::IOThreadContext ...@@ -344,14 +329,8 @@ class ServiceManagerConnectionImpl::IOThreadContext
const std::string& name) override { const std::string& name) override {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK(io_thread_checker_.CalledOnValidThread());
auto it = request_handlers_.find(name); auto it = request_handlers_.find(name);
if (it == request_handlers_.end()) { DCHECK(it != request_handlers_.end())
std::unique_ptr<PendingRequest> pending_request = << "Can't create service " << name << ". No handler found.";
base::MakeUnique<PendingRequest>();
pending_request->service_name = name;
pending_request->request = std::move(request);
pending_requests_.push_back(std::move(pending_request));
return;
}
it->second.Run(std::move(request)); it->second.Run(std::move(request));
} }
...@@ -413,10 +392,6 @@ class ServiceManagerConnectionImpl::IOThreadContext ...@@ -413,10 +392,6 @@ class ServiceManagerConnectionImpl::IOThreadContext
embedded_services_; embedded_services_;
std::unordered_map<std::string, ServiceRequestHandler> request_handlers_; std::unordered_map<std::string, ServiceRequestHandler> request_handlers_;
// Requests before the service have been registered are added here. Typically
// there are very few elements, so we use a vector.
std::vector<std::unique_ptr<PendingRequest>> pending_requests_;
mojo::Binding<mojom::Child> child_binding_; mojo::Binding<mojom::Child> child_binding_;
base::WeakPtrFactory<IOThreadContext> weak_factory_; base::WeakPtrFactory<IOThreadContext> weak_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment