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

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

Issue 23581006: Reland 220012: Move the functions of filebrowserPrivateApi from the file_manager namespace to the e… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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 | 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 "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" 9 #include "chrome/browser/chromeos/drive/drive_app_registry.h"
10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
11 #include "chrome/browser/chromeos/drive/logging.h" 11 #include "chrome/browser/chromeos/drive/logging.h"
12 #include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h" 12 #include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h"
13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
14 #include "chrome/browser/chromeos/extensions/file_manager/url_util.h" 14 #include "chrome/browser/chromeos/extensions/file_manager/url_util.h"
15 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" 15 #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
16 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 16 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
21 #include "webkit/common/fileapi/file_system_util.h" 21 #include "webkit/common/fileapi/file_system_util.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 namespace file_manager { 25 namespace extensions {
26 namespace { 26 namespace {
27 27
28 // List of connection types of drive. 28 // List of connection types of drive.
29 // Keep this in sync with the DriveConnectionType in volume_manager.js. 29 // Keep this in sync with the DriveConnectionType in volume_manager.js.
30 const char kDriveConnectionTypeOffline[] = "offline"; 30 const char kDriveConnectionTypeOffline[] = "offline";
31 const char kDriveConnectionTypeMetered[] = "metered"; 31 const char kDriveConnectionTypeMetered[] = "metered";
32 const char kDriveConnectionTypeOnline[] = "online"; 32 const char kDriveConnectionTypeOnline[] = "online";
33 33
34 34
35 // List of reasons of kDriveConnectionType*. 35 // List of reasons of kDriveConnectionType*.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 bool GetDriveEntryPropertiesFunction::RunImpl() { 74 bool GetDriveEntryPropertiesFunction::RunImpl() {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 76
77 std::string file_url_str; 77 std::string file_url_str;
78 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) 78 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str))
79 return false; 79 return false;
80 80
81 GURL file_url = GURL(file_url_str); 81 GURL file_url = GURL(file_url_str);
82 file_path_ = drive::util::ExtractDrivePath( 82 file_path_ = drive::util::ExtractDrivePath(
83 util::GetLocalPathFromURL(render_view_host(), profile(), file_url)); 83 file_manager::util::GetLocalPathFromURL(
84 render_view_host(), profile(), file_url));
84 85
85 properties_.reset(new base::DictionaryValue); 86 properties_.reset(new base::DictionaryValue);
86 properties_->SetString("fileUrl", file_url.spec()); 87 properties_->SetString("fileUrl", file_url.spec());
87 88
88 // Start getting the file info. 89 // Start getting the file info.
89 drive::DriveIntegrationService* integration_service = 90 drive::DriveIntegrationService* integration_service =
90 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 91 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
91 // |integration_service| is NULL if Drive is disabled. 92 // |integration_service| is NULL if Drive is disabled.
92 if (!integration_service) { 93 if (!integration_service) {
93 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); 94 CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 131
131 const drive::FileSpecificInfo& file_specific_info = 132 const drive::FileSpecificInfo& file_specific_info =
132 entry->file_specific_info(); 133 entry->file_specific_info();
133 134
134 // Get drive WebApps that can accept this file. We just need to extract the 135 // Get drive WebApps that can accept this file. We just need to extract the
135 // doc icon for the drive app, which is set as default. 136 // doc icon for the drive app, which is set as default.
136 ScopedVector<drive::DriveAppInfo> drive_apps; 137 ScopedVector<drive::DriveAppInfo> drive_apps;
137 integration_service->drive_app_registry()->GetAppsForFile( 138 integration_service->drive_app_registry()->GetAppsForFile(
138 file_path_, file_specific_info.content_mime_type(), &drive_apps); 139 file_path_, file_specific_info.content_mime_type(), &drive_apps);
139 if (!drive_apps.empty()) { 140 if (!drive_apps.empty()) {
140 std::string default_task_id = file_tasks::GetDefaultTaskIdFromPrefs( 141 std::string default_task_id =
141 *profile_->GetPrefs(), 142 file_manager::file_tasks::GetDefaultTaskIdFromPrefs(
142 file_specific_info.content_mime_type(), 143 *profile_->GetPrefs(),
143 file_path_.Extension()); 144 file_specific_info.content_mime_type(),
144 file_tasks::TaskDescriptor default_task; 145 file_path_.Extension());
145 file_tasks::ParseTaskID(default_task_id, &default_task); 146 file_manager::file_tasks::TaskDescriptor default_task;
147 file_manager::file_tasks::ParseTaskID(default_task_id, &default_task);
146 DCHECK(default_task_id.empty() || !default_task.app_id.empty()); 148 DCHECK(default_task_id.empty() || !default_task.app_id.empty());
147 for (size_t i = 0; i < drive_apps.size(); ++i) { 149 for (size_t i = 0; i < drive_apps.size(); ++i) {
148 const drive::DriveAppInfo* app_info = drive_apps[i]; 150 const drive::DriveAppInfo* app_info = drive_apps[i];
149 if (default_task.app_id == app_info->app_id) { 151 if (default_task.app_id == app_info->app_id) {
150 // The drive app is set as default. Files.app should use the doc icon. 152 // The drive app is set as default. Files.app should use the doc icon.
151 const GURL doc_icon = 153 const GURL doc_icon =
152 drive::util::FindPreferredIcon(app_info->document_icons, 154 drive::util::FindPreferredIcon(app_info->document_icons,
153 drive::util::kPreferredIconSize); 155 drive::util::kPreferredIconSize);
154 properties_->SetString("customIconUrl", doc_icon.spec()); 156 properties_->SetString("customIconUrl", doc_icon.spec());
155 } 157 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return false; 199 return false;
198 200
199 drive::DriveIntegrationService* integration_service = 201 drive::DriveIntegrationService* integration_service =
200 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 202 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
201 drive::FileSystemInterface* file_system = 203 drive::FileSystemInterface* file_system =
202 integration_service ? integration_service->file_system() : NULL; 204 integration_service ? integration_service->file_system() : NULL;
203 if (!file_system) // |file_system| is NULL if Drive is disabled. 205 if (!file_system) // |file_system| is NULL if Drive is disabled.
204 return false; 206 return false;
205 207
206 base::FilePath drive_path = 208 base::FilePath drive_path =
207 drive::util::ExtractDrivePath( 209 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL(
208 util::GetLocalPathFromURL(render_view_host(), profile(), GURL(url))); 210 render_view_host(), profile(), GURL(url)));
209 if (set_pin) { 211 if (set_pin) {
210 file_system->Pin(drive_path, 212 file_system->Pin(drive_path,
211 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); 213 base::Bind(&PinDriveFileFunction::OnPinStateSet, this));
212 } else { 214 } else {
213 file_system->Unpin(drive_path, 215 file_system->Unpin(drive_path,
214 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); 216 base::Bind(&PinDriveFileFunction::OnPinStateSet, this));
215 } 217 }
216 return true; 218 return true;
217 } 219 }
218 220
(...skipping 18 matching lines...) Expand all
237 bool GetDriveFilesFunction::RunImpl() { 239 bool GetDriveFilesFunction::RunImpl() {
238 ListValue* file_urls_as_strings = NULL; 240 ListValue* file_urls_as_strings = NULL;
239 if (!args_->GetList(0, &file_urls_as_strings)) 241 if (!args_->GetList(0, &file_urls_as_strings))
240 return false; 242 return false;
241 243
242 // Convert the list of strings to a list of GURLs. 244 // Convert the list of strings to a list of GURLs.
243 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { 245 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) {
244 std::string file_url_as_string; 246 std::string file_url_as_string;
245 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) 247 if (!file_urls_as_strings->GetString(i, &file_url_as_string))
246 return false; 248 return false;
247 const base::FilePath path = util::GetLocalPathFromURL( 249 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
248 render_view_host(), profile(), GURL(file_url_as_string)); 250 render_view_host(), profile(), GURL(file_url_as_string));
249 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 251 DCHECK(drive::util::IsUnderDriveMountPoint(path));
250 base::FilePath drive_path = drive::util::ExtractDrivePath(path); 252 base::FilePath drive_path = drive::util::ExtractDrivePath(path);
251 remaining_drive_paths_.push(drive_path); 253 remaining_drive_paths_.push(drive_path);
252 } 254 }
253 255
254 local_paths_ = new ListValue; 256 local_paths_ = new ListValue;
255 GetFileOrSendResponse(); 257 GetFileOrSendResponse();
256 return true; 258 return true;
257 } 259 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (drive::IsActiveFileTransferJobInfo(jobs[i])) 339 if (drive::IsActiveFileTransferJobInfo(jobs[i]))
338 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); 340 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id);
339 } 341 }
340 342
341 // Cancel by Job ID. 343 // Cancel by Job ID.
342 scoped_ptr<ListValue> responses(new ListValue()); 344 scoped_ptr<ListValue> responses(new ListValue());
343 for (size_t i = 0; i < url_list->GetSize(); ++i) { 345 for (size_t i = 0; i < url_list->GetSize(); ++i) {
344 std::string url_as_string; 346 std::string url_as_string;
345 url_list->GetString(i, &url_as_string); 347 url_list->GetString(i, &url_as_string);
346 348
347 base::FilePath file_path = util::GetLocalPathFromURL( 349 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
348 render_view_host(), profile(), GURL(url_as_string)); 350 render_view_host(), profile(), GURL(url_as_string));
349 if (file_path.empty()) 351 if (file_path.empty())
350 continue; 352 continue;
351 353
352 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); 354 DCHECK(drive::util::IsUnderDriveMountPoint(file_path));
353 file_path = drive::util::ExtractDrivePath(file_path); 355 file_path = drive::util::ExtractDrivePath(file_path);
354 scoped_ptr<DictionaryValue> result(new DictionaryValue()); 356 scoped_ptr<DictionaryValue> result(new DictionaryValue());
355 357
356 // Cancel all the jobs for the file. 358 // Cancel all the jobs for the file.
357 PathToIdMap::iterator it = path_to_id_map.find(file_path); 359 PathToIdMap::iterator it = path_to_id_map.find(file_path);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 } 645 }
644 646
645 GetShareUrlFunction::~GetShareUrlFunction() { 647 GetShareUrlFunction::~GetShareUrlFunction() {
646 } 648 }
647 649
648 bool GetShareUrlFunction::RunImpl() { 650 bool GetShareUrlFunction::RunImpl() {
649 std::string file_url; 651 std::string file_url;
650 if (!args_->GetString(0, &file_url)) 652 if (!args_->GetString(0, &file_url))
651 return false; 653 return false;
652 654
653 const base::FilePath path = util::GetLocalPathFromURL( 655 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
654 render_view_host(), profile(), GURL(file_url)); 656 render_view_host(), profile(), GURL(file_url));
655 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 657 DCHECK(drive::util::IsUnderDriveMountPoint(path));
656 658
657 base::FilePath drive_path = drive::util::ExtractDrivePath(path); 659 base::FilePath drive_path = drive::util::ExtractDrivePath(path);
658 660
659 drive::DriveIntegrationService* integration_service = 661 drive::DriveIntegrationService* integration_service =
660 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 662 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
661 // |integration_service| is NULL if Drive is disabled. 663 // |integration_service| is NULL if Drive is disabled.
662 if (!integration_service) 664 if (!integration_service)
663 return false; 665 return false;
664 666
665 integration_service->file_system()->GetShareUrl( 667 integration_service->file_system()->GetShareUrl(
666 drive_path, 668 drive_path,
667 util::GetFileManagerBaseUrl(), // embed origin 669 file_manager::util::GetFileManagerBaseUrl(), // embed origin
668 base::Bind(&GetShareUrlFunction::OnGetShareUrl, this)); 670 base::Bind(&GetShareUrlFunction::OnGetShareUrl, this));
669 return true; 671 return true;
670 } 672 }
671 673
672 674
673 void GetShareUrlFunction::OnGetShareUrl(drive::FileError error, 675 void GetShareUrlFunction::OnGetShareUrl(drive::FileError error,
674 const GURL& share_url) { 676 const GURL& share_url) {
675 if (error != drive::FILE_ERROR_OK) { 677 if (error != drive::FILE_ERROR_OK) {
676 error_ = "Share Url for this item is not available."; 678 error_ = "Share Url for this item is not available.";
677 SendResponse(false); 679 SendResponse(false);
678 return; 680 return;
679 } 681 }
680 682
681 SetResult(new base::StringValue(share_url.spec())); 683 SetResult(new base::StringValue(share_url.spec()));
682 SendResponse(true); 684 SendResponse(true);
683 } 685 }
684 686
685 } // namespace file_manager 687 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698