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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_misc.cc

Issue 2335213004: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: Created 4 years, 3 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
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 "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "url/gurl.h" 57 #include "url/gurl.h"
58 58
59 namespace extensions { 59 namespace extensions {
60 namespace { 60 namespace {
61 61
62 using api::file_manager_private::ProfileInfo; 62 using api::file_manager_private::ProfileInfo;
63 63
64 const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore"; 64 const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore";
65 65
66 // Obtains the current app window. 66 // Obtains the current app window.
67 AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) { 67 AppWindow* GetCurrentAppWindow(UIThreadExtensionFunction* function) {
68 content::WebContents* const contents = function->GetSenderWebContents(); 68 content::WebContents* const contents = function->GetSenderWebContents();
69 return contents ? 69 return contents
70 AppWindowRegistry::Get(function->GetProfile())-> 70 ? AppWindowRegistry::Get(function->browser_context())
71 GetAppWindowForWebContents(contents) : nullptr; 71 ->GetAppWindowForWebContents(contents)
72 : nullptr;
72 } 73 }
73 74
74 std::vector<ProfileInfo> GetLoggedInProfileInfoList() { 75 std::vector<ProfileInfo> GetLoggedInProfileInfoList() {
75 DCHECK(user_manager::UserManager::IsInitialized()); 76 DCHECK(user_manager::UserManager::IsInitialized());
76 const std::vector<Profile*>& profiles = 77 const std::vector<Profile*>& profiles =
77 g_browser_process->profile_manager()->GetLoadedProfiles(); 78 g_browser_process->profile_manager()->GetLoadedProfiles();
78 std::set<Profile*> original_profiles; 79 std::set<Profile*> original_profiles;
79 std::vector<ProfileInfo> result_profiles; 80 std::vector<ProfileInfo> result_profiles;
80 81
81 for (Profile* profile : profiles) { 82 for (Profile* profile : profiles) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 // Erase duplicates. 147 // Erase duplicates.
147 std::sort(paths->begin(), paths->end()); 148 std::sort(paths->begin(), paths->end());
148 paths->erase(std::unique(paths->begin(), paths->end()), paths->end()); 149 paths->erase(std::unique(paths->begin(), paths->end()), paths->end());
149 150
150 return true; 151 return true;
151 } 152 }
152 153
153 } // namespace 154 } // namespace
154 155
155 bool FileManagerPrivateLogoutUserForReauthenticationFunction::RunSync() { 156 ExtensionFunction::ResponseAction
157 FileManagerPrivateLogoutUserForReauthenticationFunction::Run() {
156 const user_manager::User* user = 158 const user_manager::User* user =
157 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); 159 chromeos::ProfileHelper::Get()->GetUserByProfile(
160 Profile::FromBrowserContext(browser_context()));
158 if (user) { 161 if (user) {
159 user_manager::UserManager::Get()->SaveUserOAuthStatus( 162 user_manager::UserManager::Get()->SaveUserOAuthStatus(
160 user->GetAccountId(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); 163 user->GetAccountId(), user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
161 } 164 }
162 165
163 chrome::AttemptUserExit(); 166 chrome::AttemptUserExit();
164 return true; 167 return RespondNow(NoArguments());
165 } 168 }
166 169
167 bool FileManagerPrivateGetPreferencesFunction::RunSync() { 170 ExtensionFunction::ResponseAction
171 FileManagerPrivateGetPreferencesFunction::Run() {
168 api::file_manager_private::Preferences result; 172 api::file_manager_private::Preferences result;
169 const PrefService* const service = GetProfile()->GetPrefs(); 173 Profile* profile = Profile::FromBrowserContext(browser_context());
174 const PrefService* const service = profile->GetPrefs();
170 175
171 result.drive_enabled = drive::util::IsDriveEnabledForProfile(GetProfile()); 176 result.drive_enabled = drive::util::IsDriveEnabledForProfile(profile);
172 result.cellular_disabled = 177 result.cellular_disabled =
173 service->GetBoolean(drive::prefs::kDisableDriveOverCellular); 178 service->GetBoolean(drive::prefs::kDisableDriveOverCellular);
174 result.hosted_files_disabled = 179 result.hosted_files_disabled =
175 service->GetBoolean(drive::prefs::kDisableDriveHostedFiles); 180 service->GetBoolean(drive::prefs::kDisableDriveHostedFiles);
176 result.search_suggest_enabled = 181 result.search_suggest_enabled =
177 service->GetBoolean(prefs::kSearchSuggestEnabled); 182 service->GetBoolean(prefs::kSearchSuggestEnabled);
178 result.use24hour_clock = service->GetBoolean(prefs::kUse24HourClock); 183 result.use24hour_clock = service->GetBoolean(prefs::kUse24HourClock);
179 result.allow_redeem_offers = true; 184 result.allow_redeem_offers = true;
180 if (!chromeos::CrosSettings::Get()->GetBoolean( 185 if (!chromeos::CrosSettings::Get()->GetBoolean(
181 chromeos::kAllowRedeemChromeOsRegistrationOffers, 186 chromeos::kAllowRedeemChromeOsRegistrationOffers,
182 &result.allow_redeem_offers)) { 187 &result.allow_redeem_offers)) {
183 result.allow_redeem_offers = true; 188 result.allow_redeem_offers = true;
184 } 189 }
185 result.timezone = 190 result.timezone =
186 UTF16ToUTF8(chromeos::system::TimezoneSettings::GetInstance() 191 UTF16ToUTF8(chromeos::system::TimezoneSettings::GetInstance()
187 ->GetCurrentTimezoneID()); 192 ->GetCurrentTimezoneID());
188 193
189 SetResult(result.ToValue()); 194 drive::EventLogger* logger = file_manager::util::GetLogger(profile);
190
191 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
192 if (logger) 195 if (logger)
193 logger->Log(logging::LOG_INFO, "%s succeeded.", name()); 196 logger->Log(logging::LOG_INFO, "%s succeeded.", name());
194 return true; 197
198 return RespondNow(OneArgument(result.ToValue()));
195 } 199 }
196 200
197 bool FileManagerPrivateSetPreferencesFunction::RunSync() { 201 ExtensionFunction::ResponseAction
202 FileManagerPrivateSetPreferencesFunction::Run() {
198 using extensions::api::file_manager_private::SetPreferences::Params; 203 using extensions::api::file_manager_private::SetPreferences::Params;
199 const std::unique_ptr<Params> params(Params::Create(*args_)); 204 const std::unique_ptr<Params> params(Params::Create(*args_));
200 EXTENSION_FUNCTION_VALIDATE(params); 205 EXTENSION_FUNCTION_VALIDATE(params);
201 206
202 PrefService* const service = GetProfile()->GetPrefs(); 207 Profile* profile = Profile::FromBrowserContext(browser_context());
208 PrefService* const service = profile->GetPrefs();
203 209
204 if (params->change_info.cellular_disabled) 210 if (params->change_info.cellular_disabled)
205 service->SetBoolean(drive::prefs::kDisableDriveOverCellular, 211 service->SetBoolean(drive::prefs::kDisableDriveOverCellular,
206 *params->change_info.cellular_disabled); 212 *params->change_info.cellular_disabled);
207 213
208 if (params->change_info.hosted_files_disabled) 214 if (params->change_info.hosted_files_disabled)
209 service->SetBoolean(drive::prefs::kDisableDriveHostedFiles, 215 service->SetBoolean(drive::prefs::kDisableDriveHostedFiles,
210 *params->change_info.hosted_files_disabled); 216 *params->change_info.hosted_files_disabled);
211 217
212 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); 218 drive::EventLogger* logger = file_manager::util::GetLogger(profile);
213 if (logger) 219 if (logger)
214 logger->Log(logging::LOG_INFO, "%s succeeded.", name()); 220 logger->Log(logging::LOG_INFO, "%s succeeded.", name());
215 return true; 221 return RespondNow(NoArguments());
216 } 222 }
217 223
218 FileManagerPrivateInternalZipSelectionFunction:: 224 FileManagerPrivateInternalZipSelectionFunction::
219 FileManagerPrivateInternalZipSelectionFunction() {} 225 FileManagerPrivateInternalZipSelectionFunction() {}
220 226
221 FileManagerPrivateInternalZipSelectionFunction:: 227 FileManagerPrivateInternalZipSelectionFunction::
222 ~FileManagerPrivateInternalZipSelectionFunction() {} 228 ~FileManagerPrivateInternalZipSelectionFunction() {}
223 229
224 bool FileManagerPrivateInternalZipSelectionFunction::RunAsync() { 230 bool FileManagerPrivateInternalZipSelectionFunction::RunAsync() {
225 using extensions::api::file_manager_private_internal::ZipSelection::Params; 231 using extensions::api::file_manager_private_internal::ZipSelection::Params;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 src_dir, src_relative_paths, dest_file)) 281 src_dir, src_relative_paths, dest_file))
276 ->Start(); 282 ->Start();
277 return true; 283 return true;
278 } 284 }
279 285
280 void FileManagerPrivateInternalZipSelectionFunction::OnZipDone(bool success) { 286 void FileManagerPrivateInternalZipSelectionFunction::OnZipDone(bool success) {
281 SetResult(base::MakeUnique<base::FundamentalValue>(success)); 287 SetResult(base::MakeUnique<base::FundamentalValue>(success));
282 SendResponse(true); 288 SendResponse(true);
283 } 289 }
284 290
285 bool FileManagerPrivateZoomFunction::RunSync() { 291 ExtensionFunction::ResponseAction FileManagerPrivateZoomFunction::Run() {
286 using extensions::api::file_manager_private::Zoom::Params; 292 using extensions::api::file_manager_private::Zoom::Params;
287 const std::unique_ptr<Params> params(Params::Create(*args_)); 293 const std::unique_ptr<Params> params(Params::Create(*args_));
288 EXTENSION_FUNCTION_VALIDATE(params); 294 EXTENSION_FUNCTION_VALIDATE(params);
289 295
290 content::PageZoom zoom_type; 296 content::PageZoom zoom_type;
291 switch (params->operation) { 297 switch (params->operation) {
292 case api::file_manager_private::ZOOM_OPERATION_TYPE_IN: 298 case api::file_manager_private::ZOOM_OPERATION_TYPE_IN:
293 zoom_type = content::PAGE_ZOOM_IN; 299 zoom_type = content::PAGE_ZOOM_IN;
294 break; 300 break;
295 case api::file_manager_private::ZOOM_OPERATION_TYPE_OUT: 301 case api::file_manager_private::ZOOM_OPERATION_TYPE_OUT:
296 zoom_type = content::PAGE_ZOOM_OUT; 302 zoom_type = content::PAGE_ZOOM_OUT;
297 break; 303 break;
298 case api::file_manager_private::ZOOM_OPERATION_TYPE_RESET: 304 case api::file_manager_private::ZOOM_OPERATION_TYPE_RESET:
299 zoom_type = content::PAGE_ZOOM_RESET; 305 zoom_type = content::PAGE_ZOOM_RESET;
300 break; 306 break;
301 default: 307 default:
302 NOTREACHED(); 308 NOTREACHED();
303 return false; 309 return RespondNow(Error(kUnknownErrorDoNotUse));
304 } 310 }
305 zoom::PageZoom::Zoom(GetSenderWebContents(), zoom_type); 311 zoom::PageZoom::Zoom(GetSenderWebContents(), zoom_type);
306 return true; 312 return RespondNow(NoArguments());
307 } 313 }
308 314
309 FileManagerPrivateRequestWebStoreAccessTokenFunction:: 315 FileManagerPrivateRequestWebStoreAccessTokenFunction::
310 FileManagerPrivateRequestWebStoreAccessTokenFunction() { 316 FileManagerPrivateRequestWebStoreAccessTokenFunction() {
311 } 317 }
312 318
313 FileManagerPrivateRequestWebStoreAccessTokenFunction:: 319 FileManagerPrivateRequestWebStoreAccessTokenFunction::
314 ~FileManagerPrivateRequestWebStoreAccessTokenFunction() { 320 ~FileManagerPrivateRequestWebStoreAccessTokenFunction() {
315 } 321 }
316 322
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 if (logger) { 371 if (logger) {
366 logger->Log(logging::LOG_ERROR, 372 logger->Log(logging::LOG_ERROR,
367 "CWS OAuth token fetch failed. (DriveApiErrorCode: %s)", 373 "CWS OAuth token fetch failed. (DriveApiErrorCode: %s)",
368 google_apis::DriveApiErrorCodeToString(code).c_str()); 374 google_apis::DriveApiErrorCodeToString(code).c_str());
369 } 375 }
370 SetResult(base::Value::CreateNullValue()); 376 SetResult(base::Value::CreateNullValue());
371 SendResponse(false); 377 SendResponse(false);
372 } 378 }
373 } 379 }
374 380
375 bool FileManagerPrivateGetProfilesFunction::RunSync() { 381 ExtensionFunction::ResponseAction FileManagerPrivateGetProfilesFunction::Run() {
376 const std::vector<ProfileInfo>& profiles = GetLoggedInProfileInfoList(); 382 const std::vector<ProfileInfo>& profiles = GetLoggedInProfileInfoList();
377 383
378 // Obtains the display profile ID. 384 // Obtains the display profile ID.
379 AppWindow* const app_window = GetCurrentAppWindow(this); 385 AppWindow* const app_window = GetCurrentAppWindow(this);
380 chrome::MultiUserWindowManager* const window_manager = 386 chrome::MultiUserWindowManager* const window_manager =
381 chrome::MultiUserWindowManager::GetInstance(); 387 chrome::MultiUserWindowManager::GetInstance();
382 const AccountId current_profile_id = 388 const AccountId current_profile_id = multi_user_util::GetAccountIdFromProfile(
383 multi_user_util::GetAccountIdFromProfile(GetProfile()); 389 Profile::FromBrowserContext(browser_context()));
384 const AccountId display_profile_id = 390 const AccountId display_profile_id =
385 window_manager && app_window 391 window_manager && app_window
386 ? window_manager->GetUserPresentingWindow( 392 ? window_manager->GetUserPresentingWindow(
387 app_window->GetNativeWindow()) 393 app_window->GetNativeWindow())
388 : EmptyAccountId(); 394 : EmptyAccountId();
389 395
390 results_ = api::file_manager_private::GetProfiles::Results::Create( 396 return RespondNow(
391 profiles, current_profile_id.GetUserEmail(), 397 ArgumentList(api::file_manager_private::GetProfiles::Results::Create(
392 display_profile_id.is_valid() ? display_profile_id.GetUserEmail() 398 profiles, current_profile_id.GetUserEmail(),
393 : current_profile_id.GetUserEmail()); 399 display_profile_id.is_valid() ? display_profile_id.GetUserEmail()
394 return true; 400 : current_profile_id.GetUserEmail())));
395 } 401 }
396 402
397 bool FileManagerPrivateOpenInspectorFunction::RunSync() { 403 ExtensionFunction::ResponseAction
404 FileManagerPrivateOpenInspectorFunction::Run() {
398 using extensions::api::file_manager_private::OpenInspector::Params; 405 using extensions::api::file_manager_private::OpenInspector::Params;
399 const std::unique_ptr<Params> params(Params::Create(*args_)); 406 const std::unique_ptr<Params> params(Params::Create(*args_));
400 EXTENSION_FUNCTION_VALIDATE(params); 407 EXTENSION_FUNCTION_VALIDATE(params);
401 408
402 switch (params->type) { 409 switch (params->type) {
403 case extensions::api::file_manager_private::INSPECTION_TYPE_NORMAL: 410 case extensions::api::file_manager_private::INSPECTION_TYPE_NORMAL:
404 // Open inspector for foreground page. 411 // Open inspector for foreground page.
405 DevToolsWindow::OpenDevToolsWindow(GetSenderWebContents()); 412 DevToolsWindow::OpenDevToolsWindow(GetSenderWebContents());
406 break; 413 break;
407 case extensions::api::file_manager_private::INSPECTION_TYPE_CONSOLE: 414 case extensions::api::file_manager_private::INSPECTION_TYPE_CONSOLE:
408 // Open inspector for foreground page and bring focus to the console. 415 // Open inspector for foreground page and bring focus to the console.
409 DevToolsWindow::OpenDevToolsWindow(GetSenderWebContents(), 416 DevToolsWindow::OpenDevToolsWindow(GetSenderWebContents(),
410 DevToolsToggleAction::ShowConsole()); 417 DevToolsToggleAction::ShowConsole());
411 break; 418 break;
412 case extensions::api::file_manager_private::INSPECTION_TYPE_ELEMENT: 419 case extensions::api::file_manager_private::INSPECTION_TYPE_ELEMENT:
413 // Open inspector for foreground page in inspect element mode. 420 // Open inspector for foreground page in inspect element mode.
414 DevToolsWindow::OpenDevToolsWindow(GetSenderWebContents(), 421 DevToolsWindow::OpenDevToolsWindow(GetSenderWebContents(),
415 DevToolsToggleAction::Inspect()); 422 DevToolsToggleAction::Inspect());
416 break; 423 break;
417 case extensions::api::file_manager_private::INSPECTION_TYPE_BACKGROUND: 424 case extensions::api::file_manager_private::INSPECTION_TYPE_BACKGROUND:
418 // Open inspector for background page. 425 // Open inspector for background page.
419 extensions::devtools_util::InspectBackgroundPage(extension(), 426 extensions::devtools_util::InspectBackgroundPage(
420 GetProfile()); 427 extension(), Profile::FromBrowserContext(browser_context()));
421 break; 428 break;
422 default: 429 default:
423 NOTREACHED(); 430 NOTREACHED();
424 SetError( 431 return RespondNow(Error(
425 base::StringPrintf("Unexpected inspection type(%d) is specified.", 432 base::StringPrintf("Unexpected inspection type(%d) is specified.",
426 static_cast<int>(params->type))); 433 static_cast<int>(params->type))));
427 return false;
428 } 434 }
429 return true; 435 return RespondNow(NoArguments());
430 } 436 }
431 437
432 FileManagerPrivateInternalGetMimeTypeFunction:: 438 FileManagerPrivateInternalGetMimeTypeFunction::
433 FileManagerPrivateInternalGetMimeTypeFunction() { 439 FileManagerPrivateInternalGetMimeTypeFunction() {
434 } 440 }
435 441
436 FileManagerPrivateInternalGetMimeTypeFunction:: 442 FileManagerPrivateInternalGetMimeTypeFunction::
437 ~FileManagerPrivateInternalGetMimeTypeFunction() { 443 ~FileManagerPrivateInternalGetMimeTypeFunction() {
438 } 444 }
439 445
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 base::File::Error result) { 694 base::File::Error result) {
689 if (result != base::File::FILE_OK) { 695 if (result != base::File::FILE_OK) {
690 Respond(Error("Failed to execute the action.")); 696 Respond(Error("Failed to execute the action."));
691 return; 697 return;
692 } 698 }
693 699
694 Respond(NoArguments()); 700 Respond(NoArguments());
695 } 701 }
696 702
697 } // namespace extensions 703 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698