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

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

Issue 14579006: Start app shim when app launched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment 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
« no previous file with comments | « apps/app_shim/app_shim_host_mac.h ('k') | apps/app_shim/app_shim_host_mac_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 void AppShimHost::OnChannelError() { 57 void AppShimHost::OnChannelError() {
58 Close(); 58 Close();
59 } 59 }
60 60
61 bool AppShimHost::Send(IPC::Message* message) { 61 bool AppShimHost::Send(IPC::Message* message) {
62 DCHECK(channel_.get()); 62 DCHECK(channel_.get());
63 return channel_->Send(message); 63 return channel_->Send(message);
64 } 64 }
65 65
66 void AppShimHost::OnLaunchApp(std::string profile_dir, std::string app_id) { 66 void AppShimHost::OnLaunchApp(base::FilePath profile_dir,
67 std::string app_id,
68 apps::AppShimLaunchType launch_type) {
67 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
68 DCHECK(!profile_); 70 DCHECK(!profile_);
69 if (profile_) { 71 if (profile_) {
70 // Only one app launch message per channel. 72 // Only one app launch message per channel.
71 Send(new AppShimMsg_LaunchApp_Done(false)); 73 Send(new AppShimMsg_LaunchApp_Done(false));
72 return; 74 return;
73 } 75 }
74 76
75 profile_ = FetchProfileForDirectory(profile_dir); 77 if (!(profile_ = FetchProfileForDirectory(profile_dir))) {
78 Send(new AppShimMsg_LaunchApp_Done(false));
79 return;
80 }
81
76 app_id_ = app_id; 82 app_id_ = app_id;
83
77 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); 84 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
78 bool success = handler && handler->OnShimLaunch(this); 85 bool success = handler && handler->OnShimLaunch(this, launch_type);
79 Send(new AppShimMsg_LaunchApp_Done(success)); 86 Send(new AppShimMsg_LaunchApp_Done(success));
80 } 87 }
81 88
82 void AppShimHost::OnFocus() { 89 void AppShimHost::OnFocus() {
83 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
84 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); 91 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
85 if (handler) 92 if (handler)
86 handler->OnShimFocus(this); 93 handler->OnShimFocus(this);
87 } 94 }
88 95
89 void AppShimHost::OnQuit() { 96 void AppShimHost::OnQuit() {
90 DCHECK(CalledOnValidThread()); 97 DCHECK(CalledOnValidThread());
91 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); 98 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
92 if (handler) 99 if (handler)
93 handler->OnShimQuit(this); 100 handler->OnShimQuit(this);
94 } 101 }
95 102
96 Profile* AppShimHost::FetchProfileForDirectory(const std::string& profile_dir) { 103 Profile* AppShimHost::FetchProfileForDirectory(
104 const base::FilePath& profile_dir) {
97 ProfileManager* profileManager = g_browser_process->profile_manager(); 105 ProfileManager* profileManager = g_browser_process->profile_manager();
98 // Even though the name of this function is "unsafe", there's no security 106 // Check for the profile name in the profile info cache to ensure that we
99 // issue here -- the check for the profile name in the profile info cache 107 // never access any directory that isn't a known profile.
100 // ensures that we never access any directory that isn't a known profile. 108 base::FilePath path = profileManager->user_data_dir().Append(profile_dir);
101 base::FilePath path = base::FilePath::FromUTF8Unsafe(profile_dir);
102 path = profileManager->user_data_dir().Append(path);
103 ProfileInfoCache& cache = profileManager->GetProfileInfoCache(); 109 ProfileInfoCache& cache = profileManager->GetProfileInfoCache();
104 // This ensures that the given profile path is acutally a profile that we
105 // already know about.
106 if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) { 110 if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) {
107 LOG(ERROR) << "Requested directory is not a known profile '" 111 LOG(ERROR) << "Requested directory is not a known profile '"
108 << profile_dir << "'."; 112 << profile_dir.value() << "'.";
109 return NULL; 113 return NULL;
110 } 114 }
111 Profile* profile = profileManager->GetProfile(path); 115 Profile* profile = profileManager->GetProfile(path);
112 if (!profile) { 116 if (!profile) {
113 LOG(ERROR) << "Couldn't get profile for directory '" << profile_dir << "'."; 117 LOG(ERROR) << "Couldn't get profile for directory '"
118 << profile_dir.value() << "'.";
114 return NULL; 119 return NULL;
115 } 120 }
116 return profile; 121 return profile;
117 } 122 }
118 123
119 void AppShimHost::OnAppClosed() { 124 void AppShimHost::OnAppClosed() {
120 Close(); 125 Close();
121 } 126 }
122 127
123 void AppShimHost::Close() { 128 void AppShimHost::Close() {
124 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
125 delete this; 130 delete this;
126 } 131 }
OLDNEW
« no previous file with comments | « apps/app_shim/app_shim_host_mac.h ('k') | apps/app_shim/app_shim_host_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698