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

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

Issue 1829783002: [Extensions] Convert APIs to use movable types [5] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "content/public/common/page_zoom.h" 51 #include "content/public/common/page_zoom.h"
52 #include "extensions/browser/app_window/app_window.h" 52 #include "extensions/browser/app_window/app_window.h"
53 #include "extensions/browser/app_window/app_window_registry.h" 53 #include "extensions/browser/app_window/app_window_registry.h"
54 #include "google_apis/drive/auth_service.h" 54 #include "google_apis/drive/auth_service.h"
55 #include "ui/base/webui/web_ui_util.h" 55 #include "ui/base/webui/web_ui_util.h"
56 #include "url/gurl.h" 56 #include "url/gurl.h"
57 57
58 namespace extensions { 58 namespace extensions {
59 namespace { 59 namespace {
60 60
61 using api::file_manager_private::ProfileInfo;
62
61 const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore"; 63 const char kCWSScope[] = "https://www.googleapis.com/auth/chromewebstore";
62 64
63 // Obtains the current app window. 65 // Obtains the current app window.
64 AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) { 66 AppWindow* GetCurrentAppWindow(ChromeSyncExtensionFunction* function) {
65 content::WebContents* const contents = function->GetSenderWebContents(); 67 content::WebContents* const contents = function->GetSenderWebContents();
66 return contents ? 68 return contents ?
67 AppWindowRegistry::Get(function->GetProfile())-> 69 AppWindowRegistry::Get(function->GetProfile())->
68 GetAppWindowForWebContents(contents) : nullptr; 70 GetAppWindowForWebContents(contents) : nullptr;
69 } 71 }
70 72
71 std::vector<linked_ptr<api::file_manager_private::ProfileInfo> > 73 std::vector<ProfileInfo> GetLoggedInProfileInfoList() {
72 GetLoggedInProfileInfoList() {
73 DCHECK(user_manager::UserManager::IsInitialized()); 74 DCHECK(user_manager::UserManager::IsInitialized());
74 const std::vector<Profile*>& profiles = 75 const std::vector<Profile*>& profiles =
75 g_browser_process->profile_manager()->GetLoadedProfiles(); 76 g_browser_process->profile_manager()->GetLoadedProfiles();
76 std::set<Profile*> original_profiles; 77 std::set<Profile*> original_profiles;
77 std::vector<linked_ptr<api::file_manager_private::ProfileInfo> > 78 std::vector<ProfileInfo> result_profiles;
78 result_profiles;
79 79
80 for (size_t i = 0; i < profiles.size(); ++i) { 80 for (Profile* profile : profiles) {
81 // Filter the profile. 81 // Filter the profile.
82 Profile* const profile = profiles[i]->GetOriginalProfile(); 82 profile = profile->GetOriginalProfile();
83 if (original_profiles.count(profile)) 83 if (original_profiles.count(profile))
84 continue; 84 continue;
85 original_profiles.insert(profile); 85 original_profiles.insert(profile);
86 const user_manager::User* const user = 86 const user_manager::User* const user =
87 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 87 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
88 if (!user || !user->is_logged_in()) 88 if (!user || !user->is_logged_in())
89 continue; 89 continue;
90 90
91 // Make a ProfileInfo. 91 // Make a ProfileInfo.
92 linked_ptr<api::file_manager_private::ProfileInfo> profile_info( 92 ProfileInfo profile_info;
93 new api::file_manager_private::ProfileInfo()); 93 profile_info.profile_id =
94 profile_info->profile_id =
95 multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail(); 94 multi_user_util::GetAccountIdFromProfile(profile).GetUserEmail();
96 profile_info->display_name = UTF16ToUTF8(user->GetDisplayName()); 95 profile_info.display_name = UTF16ToUTF8(user->GetDisplayName());
97 // TODO(hirono): Remove the property from the profile_info. 96 // TODO(hirono): Remove the property from the profile_info.
98 profile_info->is_current_profile = true; 97 profile_info.is_current_profile = true;
99 98
100 result_profiles.push_back(profile_info); 99 result_profiles.push_back(std::move(profile_info));
101 } 100 }
102 101
103 return result_profiles; 102 return result_profiles;
104 } 103 }
105 104
106 // Converts a list of file system urls (as strings) to a pair of a provided file 105 // Converts a list of file system urls (as strings) to a pair of a provided file
107 // system object and a list of unique paths on the file system. In case of an 106 // system object and a list of unique paths on the file system. In case of an
108 // error, false is returned and the error message set. 107 // error, false is returned and the error message set.
109 bool ConvertURLsToProvidedInfo( 108 bool ConvertURLsToProvidedInfo(
110 const scoped_refptr<storage::FileSystemContext>& file_system_context, 109 const scoped_refptr<storage::FileSystemContext>& file_system_context,
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 logger->Log(logging::LOG_ERROR, 365 logger->Log(logging::LOG_ERROR,
367 "CWS OAuth token fetch failed. (DriveApiErrorCode: %s)", 366 "CWS OAuth token fetch failed. (DriveApiErrorCode: %s)",
368 google_apis::DriveApiErrorCodeToString(code).c_str()); 367 google_apis::DriveApiErrorCodeToString(code).c_str());
369 } 368 }
370 SetResult(base::Value::CreateNullValue()); 369 SetResult(base::Value::CreateNullValue());
371 SendResponse(false); 370 SendResponse(false);
372 } 371 }
373 } 372 }
374 373
375 bool FileManagerPrivateGetProfilesFunction::RunSync() { 374 bool FileManagerPrivateGetProfilesFunction::RunSync() {
376 const std::vector<linked_ptr<api::file_manager_private::ProfileInfo> >& 375 const std::vector<ProfileInfo>& profiles = GetLoggedInProfileInfoList();
377 profiles = GetLoggedInProfileInfoList();
378 376
379 // Obtains the display profile ID. 377 // Obtains the display profile ID.
380 AppWindow* const app_window = GetCurrentAppWindow(this); 378 AppWindow* const app_window = GetCurrentAppWindow(this);
381 chrome::MultiUserWindowManager* const window_manager = 379 chrome::MultiUserWindowManager* const window_manager =
382 chrome::MultiUserWindowManager::GetInstance(); 380 chrome::MultiUserWindowManager::GetInstance();
383 const AccountId current_profile_id = 381 const AccountId current_profile_id =
384 multi_user_util::GetAccountIdFromProfile(GetProfile()); 382 multi_user_util::GetAccountIdFromProfile(GetProfile());
385 const AccountId display_profile_id = 383 const AccountId display_profile_id =
386 window_manager && app_window 384 window_manager && app_window
387 ? window_manager->GetUserPresentingWindow( 385 ? window_manager->GetUserPresentingWindow(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 479
482 ExtensionFunction::ResponseAction 480 ExtensionFunction::ResponseAction
483 FileManagerPrivateGetProvidingExtensionsFunction::Run() { 481 FileManagerPrivateGetProvidingExtensionsFunction::Run() {
484 using chromeos::file_system_provider::Service; 482 using chromeos::file_system_provider::Service;
485 using chromeos::file_system_provider::ProvidingExtensionInfo; 483 using chromeos::file_system_provider::ProvidingExtensionInfo;
486 const Service* const service = Service::Get(chrome_details_.GetProfile()); 484 const Service* const service = Service::Get(chrome_details_.GetProfile());
487 const std::vector<ProvidingExtensionInfo> info_list = 485 const std::vector<ProvidingExtensionInfo> info_list =
488 service->GetProvidingExtensionInfoList(); 486 service->GetProvidingExtensionInfoList();
489 487
490 using api::file_manager_private::ProvidingExtension; 488 using api::file_manager_private::ProvidingExtension;
491 std::vector<linked_ptr<ProvidingExtension>> providing_extensions; 489 std::vector<ProvidingExtension> providing_extensions;
492 for (const auto& info : info_list) { 490 for (const auto& info : info_list) {
493 const linked_ptr<ProvidingExtension> providing_extension( 491 ProvidingExtension providing_extension;
494 new ProvidingExtension); 492 providing_extension.extension_id = info.extension_id;
495 providing_extension->extension_id = info.extension_id; 493 providing_extension.name = info.name;
496 providing_extension->name = info.name; 494 providing_extension.configurable = info.capabilities.configurable();
497 providing_extension->configurable = info.capabilities.configurable(); 495 providing_extension.watchable = info.capabilities.watchable();
498 providing_extension->watchable = info.capabilities.watchable(); 496 providing_extension.multiple_mounts = info.capabilities.multiple_mounts();
499 providing_extension->multiple_mounts = info.capabilities.multiple_mounts();
500 switch (info.capabilities.source()) { 497 switch (info.capabilities.source()) {
501 case SOURCE_FILE: 498 case SOURCE_FILE:
502 providing_extension->source = 499 providing_extension.source =
503 api::manifest_types::FILE_SYSTEM_PROVIDER_SOURCE_FILE; 500 api::manifest_types::FILE_SYSTEM_PROVIDER_SOURCE_FILE;
504 break; 501 break;
505 case SOURCE_DEVICE: 502 case SOURCE_DEVICE:
506 providing_extension->source = 503 providing_extension.source =
507 api::manifest_types::FILE_SYSTEM_PROVIDER_SOURCE_DEVICE; 504 api::manifest_types::FILE_SYSTEM_PROVIDER_SOURCE_DEVICE;
508 break; 505 break;
509 case SOURCE_NETWORK: 506 case SOURCE_NETWORK:
510 providing_extension->source = 507 providing_extension.source =
511 api::manifest_types::FILE_SYSTEM_PROVIDER_SOURCE_NETWORK; 508 api::manifest_types::FILE_SYSTEM_PROVIDER_SOURCE_NETWORK;
512 break; 509 break;
513 } 510 }
514 providing_extensions.push_back(providing_extension); 511 providing_extensions.push_back(std::move(providing_extension));
515 } 512 }
516 513
517 return RespondNow(ArgumentList( 514 return RespondNow(ArgumentList(
518 api::file_manager_private::GetProvidingExtensions::Results::Create( 515 api::file_manager_private::GetProvidingExtensions::Results::Create(
519 providing_extensions))); 516 providing_extensions)));
520 } 517 }
521 518
522 FileManagerPrivateAddProvidedFileSystemFunction:: 519 FileManagerPrivateAddProvidedFileSystemFunction::
523 FileManagerPrivateAddProvidedFileSystemFunction() 520 FileManagerPrivateAddProvidedFileSystemFunction()
524 : chrome_details_(this) { 521 : chrome_details_(this) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 627
631 void FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted( 628 void FileManagerPrivateInternalGetCustomActionsFunction::OnCompleted(
632 const chromeos::file_system_provider::Actions& actions, 629 const chromeos::file_system_provider::Actions& actions,
633 base::File::Error result) { 630 base::File::Error result) {
634 if (result != base::File::FILE_OK) { 631 if (result != base::File::FILE_OK) {
635 Respond(Error("Failed to fetch actions.")); 632 Respond(Error("Failed to fetch actions."));
636 return; 633 return;
637 } 634 }
638 635
639 using api::file_system_provider::Action; 636 using api::file_system_provider::Action;
640 std::vector<linked_ptr<Action>> items; 637 std::vector<Action> items;
641 for (const auto& action : actions) { 638 for (const auto& action : actions) {
642 const linked_ptr<Action> item(new Action); 639 Action item;
643 item->id = action.id; 640 item.id = action.id;
644 item->title.reset(new std::string(action.title)); 641 item.title.reset(new std::string(action.title));
645 items.push_back(item); 642 items.push_back(std::move(item));
646 } 643 }
647 644
648 Respond(ArgumentList( 645 Respond(ArgumentList(
649 api::file_manager_private_internal::GetCustomActions::Results::Create( 646 api::file_manager_private_internal::GetCustomActions::Results::Create(
650 items))); 647 items)));
651 } 648 }
652 649
653 FileManagerPrivateInternalExecuteCustomActionFunction:: 650 FileManagerPrivateInternalExecuteCustomActionFunction::
654 FileManagerPrivateInternalExecuteCustomActionFunction() 651 FileManagerPrivateInternalExecuteCustomActionFunction()
655 : chrome_details_(this) {} 652 : chrome_details_(this) {}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 base::File::Error result) { 685 base::File::Error result) {
689 if (result != base::File::FILE_OK) { 686 if (result != base::File::FILE_OK) {
690 Respond(Error("Failed to execute the action.")); 687 Respond(Error("Failed to execute the action."));
691 return; 688 return;
692 } 689 }
693 690
694 Respond(NoArguments()); 691 Respond(NoArguments());
695 } 692 }
696 693
697 } // namespace extensions 694 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698