Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: apps/app_shim/app_shim_host_mac.cc

Issue 16766003: Move ProfileLoader to chrome/browser/profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "apps/app_shim/app_shim_host_mac.h" 5 #include "apps/app_shim/app_shim_host_mac.h"
6 6
7 #include "apps/app_shim/app_shim_handler_mac.h" 7 #include "apps/app_shim/app_shim_handler_mac.h"
8 #include "apps/app_shim/app_shim_messages.h" 8 #include "apps/app_shim/app_shim_messages.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "ipc/ipc_channel_proxy.h" 15 #include "ipc/ipc_channel_proxy.h"
16 16
17 AppShimHost::AppShimHost() 17 AppShimHost::AppShimHost()
18 : channel_(NULL), profile_(NULL) { 18 : channel_(NULL),
19 profile_(NULL),
20 profile_loader_(g_browser_process->profile_manager()),
21 weak_factory_(this) {
19 } 22 }
20 23
21 AppShimHost::~AppShimHost() { 24 AppShimHost::~AppShimHost() {
22 DCHECK(CalledOnValidThread()); 25 DCHECK(CalledOnValidThread());
23 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); 26 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
24 if (handler) 27 if (handler)
25 handler->OnShimClose(this); 28 handler->OnShimClose(this);
26 } 29 }
27 30
28 void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { 31 void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 std::string app_id, 70 std::string app_id,
68 apps::AppShimLaunchType launch_type) { 71 apps::AppShimLaunchType launch_type) {
69 DCHECK(CalledOnValidThread()); 72 DCHECK(CalledOnValidThread());
70 DCHECK(!profile_); 73 DCHECK(!profile_);
71 if (profile_) { 74 if (profile_) {
72 // Only one app launch message per channel. 75 // Only one app launch message per channel.
73 Send(new AppShimMsg_LaunchApp_Done(false)); 76 Send(new AppShimMsg_LaunchApp_Done(false));
74 return; 77 return;
75 } 78 }
76 79
77 if (!(profile_ = FetchProfileForDirectory(profile_dir))) { 80 LoadProfile(profile_dir,
78 Send(new AppShimMsg_LaunchApp_Done(false)); 81 base::Bind(&AppShimHost::LaunchAppWithProfile,
79 return; 82 weak_factory_.GetWeakPtr(), app_id, launch_type));
80 }
81
82 app_id_ = app_id;
83
84 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
85 bool success = handler && handler->OnShimLaunch(this, launch_type);
86 Send(new AppShimMsg_LaunchApp_Done(success));
87 } 83 }
88 84
89 void AppShimHost::OnFocus() { 85 void AppShimHost::OnFocus() {
90 DCHECK(CalledOnValidThread()); 86 DCHECK(CalledOnValidThread());
91 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); 87 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
92 if (handler) 88 if (handler)
93 handler->OnShimFocus(this); 89 handler->OnShimFocus(this);
94 } 90 }
95 91
96 void AppShimHost::OnQuit() { 92 void AppShimHost::OnQuit() {
97 DCHECK(CalledOnValidThread()); 93 DCHECK(CalledOnValidThread());
98 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); 94 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
99 if (handler) 95 if (handler)
100 handler->OnShimQuit(this); 96 handler->OnShimQuit(this);
101 } 97 }
102 98
103 Profile* AppShimHost::FetchProfileForDirectory( 99 void AppShimHost::LoadProfile(const base::FilePath& profile_dir,
104 const base::FilePath& profile_dir) { 100 base::Callback<void(Profile*)> callback) {
105 ProfileManager* profileManager = g_browser_process->profile_manager(); 101 profile_loader_.LoadProfileInvalidatingOtherLoads(
106 // Check for the profile name in the profile info cache to ensure that we 102 g_browser_process->profile_manager()->user_data_dir().Append(profile_dir),
107 // never access any directory that isn't a known profile. 103 callback);
108 base::FilePath path = profileManager->user_data_dir().Append(profile_dir); 104 }
109 ProfileInfoCache& cache = profileManager->GetProfileInfoCache(); 105
110 if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) { 106 void AppShimHost::LaunchAppWithProfile(const std::string& app_id,
111 LOG(ERROR) << "Requested directory is not a known profile '" 107 apps::AppShimLaunchType launch_type,
112 << profile_dir.value() << "'."; 108 Profile* profile) {
113 return NULL; 109 if (!profile) {
tapted 2013/06/11 05:31:44 I don't think there's a way for a NULL pointer to
jackhou1 2013/06/12 09:41:32 LoadProfile now runs this callback with NULL if th
110 Send(new AppShimMsg_LaunchApp_Done(false));
111 return;
114 } 112 }
115 Profile* profile = profileManager->GetProfile(path); 113
116 if (!profile) { 114 profile_ = profile;
117 LOG(ERROR) << "Couldn't get profile for directory '" 115 app_id_ = app_id;
118 << profile_dir.value() << "'."; 116
119 return NULL; 117 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
120 } 118 bool success = handler && handler->OnShimLaunch(this, launch_type);
121 return profile; 119 Send(new AppShimMsg_LaunchApp_Done(success));
122 } 120 }
123 121
124 void AppShimHost::OnAppClosed() { 122 void AppShimHost::OnAppClosed() {
125 Close(); 123 Close();
126 } 124 }
127 125
128 void AppShimHost::Close() { 126 void AppShimHost::Close() {
129 DCHECK(CalledOnValidThread()); 127 DCHECK(CalledOnValidThread());
130 delete this; 128 delete this;
131 } 129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698