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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 11106007: drive: Rename 'gdata' namespace to 'drive' in chrome/browser/chromeos/drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_browser_private_api.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h"
6 6
7 #include <sys/statvfs.h> 7 #include <sys/statvfs.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void AddDriveMountPoint( 181 void AddDriveMountPoint(
182 Profile* profile, 182 Profile* profile,
183 const std::string& extension_id, 183 const std::string& extension_id,
184 content::RenderViewHost* render_view_host) { 184 content::RenderViewHost* render_view_host) {
185 fileapi::ExternalFileSystemMountPointProvider* provider = 185 fileapi::ExternalFileSystemMountPointProvider* provider =
186 BrowserContext::GetDefaultStoragePartition(profile)-> 186 BrowserContext::GetDefaultStoragePartition(profile)->
187 GetFileSystemContext()->external_provider(); 187 GetFileSystemContext()->external_provider();
188 if (!provider) 188 if (!provider)
189 return; 189 return;
190 190
191 const FilePath mount_point = gdata::util::GetDriveMountPointPath(); 191 const FilePath mount_point = drive::util::GetDriveMountPointPath();
192 if (!render_view_host || !render_view_host->GetProcess()) 192 if (!render_view_host || !render_view_host->GetProcess())
193 return; 193 return;
194 194
195 // Grant R/W permissions to drive 'folder'. File API layer still 195 // Grant R/W permissions to drive 'folder'. File API layer still
196 // expects this to be satisfied. 196 // expects this to be satisfied.
197 GrantFilePermissionsToHost(render_view_host, 197 GrantFilePermissionsToHost(render_view_host,
198 mount_point, 198 mount_point,
199 file_handler_util::GetReadWritePermissions()); 199 file_handler_util::GetReadWritePermissions());
200 200
201 // Grant R/W permission for tmp and pinned cache folder. 201 // Grant R/W permission for tmp and pinned cache folder.
202 gdata::DriveSystemService* system_service = 202 drive::DriveSystemService* system_service =
203 gdata::DriveSystemServiceFactory::GetForProfile(profile); 203 drive::DriveSystemServiceFactory::GetForProfile(profile);
204 // |system_service| is NULL if incognito window / guest login. 204 // |system_service| is NULL if incognito window / guest login.
205 if (!system_service || !system_service->file_system()) 205 if (!system_service || !system_service->file_system())
206 return; 206 return;
207 gdata::DriveCache* cache = system_service->cache(); 207 drive::DriveCache* cache = system_service->cache();
208 208
209 // We check permissions for raw cache file paths only for read-only 209 // We check permissions for raw cache file paths only for read-only
210 // operations (when fileEntry.file() is called), so read only permissions 210 // operations (when fileEntry.file() is called), so read only permissions
211 // should be sufficient for all cache paths. For the rest of supported 211 // should be sufficient for all cache paths. For the rest of supported
212 // operations the file access check is done for drive/ paths. 212 // operations the file access check is done for drive/ paths.
213 GrantFilePermissionsToHost(render_view_host, 213 GrantFilePermissionsToHost(render_view_host,
214 cache->GetCacheDirectoryPath( 214 cache->GetCacheDirectoryPath(
215 gdata::DriveCache::CACHE_TYPE_TMP), 215 drive::DriveCache::CACHE_TYPE_TMP),
216 file_handler_util::GetReadOnlyPermissions()); 216 file_handler_util::GetReadOnlyPermissions());
217 GrantFilePermissionsToHost( 217 GrantFilePermissionsToHost(
218 render_view_host, 218 render_view_host,
219 cache->GetCacheDirectoryPath( 219 cache->GetCacheDirectoryPath(
220 gdata::DriveCache::CACHE_TYPE_PERSISTENT), 220 drive::DriveCache::CACHE_TYPE_PERSISTENT),
221 file_handler_util::GetReadOnlyPermissions()); 221 file_handler_util::GetReadOnlyPermissions());
222 222
223 FilePath mount_point_virtual; 223 FilePath mount_point_virtual;
224 if (provider->GetVirtualPath(mount_point, &mount_point_virtual)) 224 if (provider->GetVirtualPath(mount_point, &mount_point_virtual))
225 provider->GrantFileAccessToExtension(extension_id, mount_point_virtual); 225 provider->GrantFileAccessToExtension(extension_id, mount_point_virtual);
226 } 226 }
227 227
228 // Finds an icon in the list of icons. If unable to find an icon of the exact 228 // Finds an icon in the list of icons. If unable to find an icon of the exact
229 // size requested, returns one with the next larger size. If all icons are 229 // size requested, returns one with the next larger size. If all icons are
230 // smaller than the preferred size, we'll return the largest one available. 230 // smaller than the preferred size, we'll return the largest one available.
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // Will finish asynchronously. 514 // Will finish asynchronously.
515 return true; 515 return true;
516 } 516 }
517 517
518 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread( 518 void RequestLocalFileSystemFunction::RespondSuccessOnUIThread(
519 const std::string& name, const GURL& root_path) { 519 const std::string& name, const GURL& root_path) {
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
521 // Add drive mount point immediately when we kick of first instance of file 521 // Add drive mount point immediately when we kick of first instance of file
522 // manager. The actual mount event will be sent to UI only when we perform 522 // manager. The actual mount event will be sent to UI only when we perform
523 // proper authentication. 523 // proper authentication.
524 if (gdata::DriveSystemService::IsDriveEnabled(profile_)) 524 if (drive::DriveSystemService::IsDriveEnabled(profile_))
525 AddDriveMountPoint(profile_, extension_id(), render_view_host()); 525 AddDriveMountPoint(profile_, extension_id(), render_view_host());
526 DictionaryValue* dict = new DictionaryValue(); 526 DictionaryValue* dict = new DictionaryValue();
527 SetResult(dict); 527 SetResult(dict);
528 dict->SetString("name", name); 528 dict->SetString("name", name);
529 dict->SetString("path", root_path.spec()); 529 dict->SetString("path", root_path.spec());
530 dict->SetInteger("error", gdata::DRIVE_FILE_OK); 530 dict->SetInteger("error", drive::DRIVE_FILE_OK);
531 SendResponse(true); 531 SendResponse(true);
532 } 532 }
533 533
534 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( 534 void RequestLocalFileSystemFunction::RespondFailedOnUIThread(
535 base::PlatformFileError error_code) { 535 base::PlatformFileError error_code) {
536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
537 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); 537 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code));
538 SendResponse(false); 538 SendResponse(false);
539 } 539 }
540 540
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( 623 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation(
624 scoped_refptr<FileBrowserEventRouter> event_router, 624 scoped_refptr<FileBrowserEventRouter> event_router,
625 const FilePath& local_path, const FilePath& unused, 625 const FilePath& local_path, const FilePath& unused,
626 const std::string& extension_id) { 626 const std::string& extension_id) {
627 event_router->RemoveFileWatch(local_path, extension_id); 627 event_router->RemoveFileWatch(local_path, extension_id);
628 return true; 628 return true;
629 } 629 }
630 630
631 // static 631 // static
632 void GetFileTasksFileBrowserFunction::IntersectAvailableDriveTasks( 632 void GetFileTasksFileBrowserFunction::IntersectAvailableDriveTasks(
633 gdata::DriveWebAppsRegistry* registry, 633 drive::DriveWebAppsRegistry* registry,
634 const FileInfoList& file_info_list, 634 const FileInfoList& file_info_list,
635 WebAppInfoMap* app_info, 635 WebAppInfoMap* app_info,
636 std::set<std::string>* available_tasks) { 636 std::set<std::string>* available_tasks) {
637 for (FileInfoList::const_iterator file_iter = file_info_list.begin(); 637 for (FileInfoList::const_iterator file_iter = file_info_list.begin();
638 file_iter != file_info_list.end(); ++file_iter) { 638 file_iter != file_info_list.end(); ++file_iter) {
639 if (file_iter->file_path.empty()) 639 if (file_iter->file_path.empty())
640 continue; 640 continue;
641 ScopedVector<gdata::DriveWebAppInfo> info; 641 ScopedVector<drive::DriveWebAppInfo> info;
642 registry->GetWebAppsForFile(file_iter->file_path, 642 registry->GetWebAppsForFile(file_iter->file_path,
643 file_iter->mime_type, &info); 643 file_iter->mime_type, &info);
644 std::vector<gdata::DriveWebAppInfo*> info_ptrs; 644 std::vector<drive::DriveWebAppInfo*> info_ptrs;
645 info.release(&info_ptrs); // so they don't go away prematurely. 645 info.release(&info_ptrs); // so they don't go away prematurely.
646 std::set<std::string> tasks_for_this_file; 646 std::set<std::string> tasks_for_this_file;
647 for (std::vector<gdata::DriveWebAppInfo*>::iterator 647 for (std::vector<drive::DriveWebAppInfo*>::iterator
648 apps = info_ptrs.begin(); apps != info_ptrs.end(); ++apps) { 648 apps = info_ptrs.begin(); apps != info_ptrs.end(); ++apps) {
649 std::pair<WebAppInfoMap::iterator, bool> insert_result = 649 std::pair<WebAppInfoMap::iterator, bool> insert_result =
650 app_info->insert(std::make_pair((*apps)->app_id, *apps)); 650 app_info->insert(std::make_pair((*apps)->app_id, *apps));
651 // TODO(gspencer): For now, the action id is always "open-with", but we 651 // TODO(gspencer): For now, the action id is always "open-with", but we
652 // could add any actions that the drive app supports. 652 // could add any actions that the drive app supports.
653 std::string task_id = file_handler_util::MakeTaskID( 653 std::string task_id = file_handler_util::MakeTaskID(
654 (*apps)->app_id, file_handler_util::kTaskDrive, "open-with"); 654 (*apps)->app_id, file_handler_util::kTaskDrive, "open-with");
655 tasks_for_this_file.insert(task_id); 655 tasks_for_this_file.insert(task_id);
656 // If we failed to insert a task_id because there was a duplicate, then we 656 // If we failed to insert a task_id because there was a duplicate, then we
657 // must delete it (since we own it). 657 // must delete it (since we own it).
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 iter != available_tasks.end(); ++iter) { 695 iter != available_tasks.end(); ++iter) {
696 VLOG(2) << " " << *iter; 696 VLOG(2) << " " << *iter;
697 } 697 }
698 } 698 }
699 } 699 }
700 } 700 }
701 } 701 }
702 702
703 // static 703 // static
704 void GetFileTasksFileBrowserFunction::CreateDriveTasks( 704 void GetFileTasksFileBrowserFunction::CreateDriveTasks(
705 gdata::DriveWebAppsRegistry* registry, 705 drive::DriveWebAppsRegistry* registry,
706 const WebAppInfoMap& app_info, 706 const WebAppInfoMap& app_info,
707 const std::set<std::string>& available_tasks, 707 const std::set<std::string>& available_tasks,
708 const std::set<std::string>& default_tasks, 708 const std::set<std::string>& default_tasks,
709 ListValue* result_list, 709 ListValue* result_list,
710 bool* default_already_set) { 710 bool* default_already_set) {
711 *default_already_set = false; 711 *default_already_set = false;
712 // OK, now we traverse the intersection of available applications for this 712 // OK, now we traverse the intersection of available applications for this
713 // list of files, adding a task for each one that is found. 713 // list of files, adding a task for each one that is found.
714 for (std::set<std::string>::const_iterator app_iter = available_tasks.begin(); 714 for (std::set<std::string>::const_iterator app_iter = available_tasks.begin();
715 app_iter != available_tasks.end(); ++app_iter) { 715 app_iter != available_tasks.end(); ++app_iter) {
716 std::string app_id; 716 std::string app_id;
717 std::string task_type; 717 std::string task_type;
718 bool result = file_handler_util::CrackTaskID( 718 bool result = file_handler_util::CrackTaskID(
719 *app_iter, &app_id, &task_type, NULL); 719 *app_iter, &app_id, &task_type, NULL);
720 DCHECK(result) << "Unable to parse Drive task id: " << *app_iter; 720 DCHECK(result) << "Unable to parse Drive task id: " << *app_iter;
721 DCHECK_EQ(task_type, file_handler_util::kTaskDrive); 721 DCHECK_EQ(task_type, file_handler_util::kTaskDrive);
722 722
723 WebAppInfoMap::const_iterator info_iter = app_info.find(app_id); 723 WebAppInfoMap::const_iterator info_iter = app_info.find(app_id);
724 DCHECK(info_iter != app_info.end()); 724 DCHECK(info_iter != app_info.end());
725 gdata::DriveWebAppInfo* info = info_iter->second; 725 drive::DriveWebAppInfo* info = info_iter->second;
726 DictionaryValue* task = new DictionaryValue; 726 DictionaryValue* task = new DictionaryValue;
727 727
728 task->SetString("taskId", *app_iter); 728 task->SetString("taskId", *app_iter);
729 task->SetString("title", info->app_name); 729 task->SetString("title", info->app_name);
730 730
731 GURL best_icon = FindPreferredIcon(info->app_icons, 731 GURL best_icon = FindPreferredIcon(info->app_icons,
732 kPreferredIconSize); 732 kPreferredIconSize);
733 if (!best_icon.is_empty()) { 733 if (!best_icon.is_empty()) {
734 task->SetString("iconUrl", best_icon.spec()); 734 task->SetString("iconUrl", best_icon.spec());
735 } 735 }
(...skipping 16 matching lines...) Expand all
752 // from drive. We'll know that they are drive apps because the extension id will 752 // from drive. We'll know that they are drive apps because the extension id will
753 // begin with kDriveTaskExtensionPrefix. 753 // begin with kDriveTaskExtensionPrefix.
754 bool GetFileTasksFileBrowserFunction::FindDriveAppTasks( 754 bool GetFileTasksFileBrowserFunction::FindDriveAppTasks(
755 const FileInfoList& file_info_list, 755 const FileInfoList& file_info_list,
756 ListValue* result_list, 756 ListValue* result_list,
757 bool* default_already_set) { 757 bool* default_already_set) {
758 758
759 if (file_info_list.empty()) 759 if (file_info_list.empty())
760 return true; 760 return true;
761 761
762 gdata::DriveSystemService* system_service = 762 drive::DriveSystemService* system_service =
763 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 763 drive::DriveSystemServiceFactory::GetForProfile(profile_);
764 // |system_service| is NULL if incognito window / guest login. We return true 764 // |system_service| is NULL if incognito window / guest login. We return true
765 // in this case because there might be other extension tasks, even if we don't 765 // in this case because there might be other extension tasks, even if we don't
766 // have any to add. 766 // have any to add.
767 if (!system_service || !system_service->webapps_registry()) 767 if (!system_service || !system_service->webapps_registry())
768 return true; 768 return true;
769 769
770 gdata::DriveWebAppsRegistry* registry = system_service->webapps_registry(); 770 drive::DriveWebAppsRegistry* registry = system_service->webapps_registry();
771 771
772 // Map of app_id to DriveWebAppInfo so we can look up the apps we've found 772 // Map of app_id to DriveWebAppInfo so we can look up the apps we've found
773 // after taking the intersection of available apps. 773 // after taking the intersection of available apps.
774 std::map<std::string, gdata::DriveWebAppInfo*> app_info; 774 std::map<std::string, drive::DriveWebAppInfo*> app_info;
775 // Set of application IDs. This will end up with the intersection of the 775 // Set of application IDs. This will end up with the intersection of the
776 // application IDs that apply to the paths in |file_paths|. 776 // application IDs that apply to the paths in |file_paths|.
777 std::set<std::string> available_tasks; 777 std::set<std::string> available_tasks;
778 778
779 IntersectAvailableDriveTasks(registry, file_info_list, 779 IntersectAvailableDriveTasks(registry, file_info_list,
780 &app_info, &available_tasks); 780 &app_info, &available_tasks);
781 std::set<std::string> default_tasks; 781 std::set<std::string> default_tasks;
782 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks); 782 FindDefaultDriveTasks(file_info_list, available_tasks, &default_tasks);
783 CreateDriveTasks(registry, app_info, available_tasks, default_tasks, 783 CreateDriveTasks(registry, app_info, available_tasks, default_tasks,
784 result_list, default_already_set); 784 result_list, default_already_set);
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 switch (mount_type) { 1341 switch (mount_type) {
1342 case chromeos::MOUNT_TYPE_INVALID: { 1342 case chromeos::MOUNT_TYPE_INVALID: {
1343 error_ = "Invalid mount type"; 1343 error_ = "Invalid mount type";
1344 SendResponse(false); 1344 SendResponse(false);
1345 break; 1345 break;
1346 } 1346 }
1347 case chromeos::MOUNT_TYPE_GDATA: { 1347 case chromeos::MOUNT_TYPE_GDATA: {
1348 const bool success = true; 1348 const bool success = true;
1349 // Pass back the drive mount point path as source path. 1349 // Pass back the drive mount point path as source path.
1350 const std::string& drive_path = 1350 const std::string& drive_path =
1351 gdata::util::GetDriveMountPointPathAsString(); 1351 drive::util::GetDriveMountPointPathAsString();
1352 SetResult(Value::CreateStringValue(drive_path)); 1352 SetResult(Value::CreateStringValue(drive_path));
1353 FileBrowserEventRouterFactory::GetForProfile(profile_)-> 1353 FileBrowserEventRouterFactory::GetForProfile(profile_)->
1354 MountDrive(base::Bind(&AddMountFunction::SendResponse, 1354 MountDrive(base::Bind(&AddMountFunction::SendResponse,
1355 this, 1355 this,
1356 success)); 1356 success));
1357 break; 1357 break;
1358 } 1358 }
1359 default: { 1359 default: {
1360 UrlList file_paths; 1360 UrlList file_paths;
1361 file_paths.push_back(GURL(file_url)); 1361 file_paths.push_back(GURL(file_url));
(...skipping 16 matching lines...) Expand all
1378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1379 1379
1380 if (!files.size()) { 1380 if (!files.size()) {
1381 SendResponse(false); 1381 SendResponse(false);
1382 return; 1382 return;
1383 } 1383 }
1384 1384
1385 const FilePath& source_path = files[0].local_path; 1385 const FilePath& source_path = files[0].local_path;
1386 const FilePath::StringType& display_name = files[0].display_name; 1386 const FilePath::StringType& display_name = files[0].display_name;
1387 // Check if the source path is under Drive cache directory. 1387 // Check if the source path is under Drive cache directory.
1388 gdata::DriveSystemService* system_service = 1388 drive::DriveSystemService* system_service =
1389 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 1389 drive::DriveSystemServiceFactory::GetForProfile(profile_);
1390 gdata::DriveCache* cache = system_service ? system_service->cache() : NULL; 1390 drive::DriveCache* cache = system_service ? system_service->cache() : NULL;
1391 if (cache && cache->IsUnderDriveCacheDirectory(source_path)) { 1391 if (cache && cache->IsUnderDriveCacheDirectory(source_path)) {
1392 cache->SetMountedStateOnUIThread( 1392 cache->SetMountedStateOnUIThread(
1393 source_path, 1393 source_path,
1394 true, 1394 true,
1395 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, 1395 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str,
1396 display_name)); 1396 display_name));
1397 } else { 1397 } else {
1398 OnMountedStateSet(mount_type_str, display_name, 1398 OnMountedStateSet(mount_type_str, display_name,
1399 gdata::DRIVE_FILE_OK, source_path); 1399 drive::DRIVE_FILE_OK, source_path);
1400 } 1400 }
1401 } 1401 }
1402 1402
1403 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, 1403 void AddMountFunction::OnMountedStateSet(const std::string& mount_type,
1404 const FilePath::StringType& file_name, 1404 const FilePath::StringType& file_name,
1405 gdata::DriveFileError error, 1405 drive::DriveFileError error,
1406 const FilePath& file_path) { 1406 const FilePath& file_path) {
1407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1408 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 1408 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
1409 // Pass back the actual source path of the mount point. 1409 // Pass back the actual source path of the mount point.
1410 SetResult(Value::CreateStringValue(file_path.value())); 1410 SetResult(Value::CreateStringValue(file_path.value()));
1411 SendResponse(true); 1411 SendResponse(true);
1412 // MountPath() takes a std::string. 1412 // MountPath() takes a std::string.
1413 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), 1413 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(),
1414 FilePath(file_name).Extension(), file_name, 1414 FilePath(file_name).Extension(), file_name,
1415 DiskMountManager::MountTypeFromString( 1415 DiskMountManager::MountTypeFromString(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 1508
1509 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread( 1509 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread(
1510 const SelectedFileInfoList& files) { 1510 const SelectedFileInfoList& files) {
1511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1512 1512
1513 if (files.size() != 1) { 1513 if (files.size() != 1) {
1514 SendResponse(false); 1514 SendResponse(false);
1515 return; 1515 return;
1516 } 1516 }
1517 1517
1518 if (files[0].file_path == gdata::util::GetDriveMountPointPath()) { 1518 if (files[0].file_path == drive::util::GetDriveMountPointPath()) {
1519 gdata::DriveSystemService* system_service = 1519 drive::DriveSystemService* system_service =
1520 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 1520 drive::DriveSystemServiceFactory::GetForProfile(profile_);
1521 1521
1522 gdata::DriveFileSystemInterface* file_system = 1522 drive::DriveFileSystemInterface* file_system =
1523 system_service->file_system(); 1523 system_service->file_system();
1524 1524
1525 file_system->GetAvailableSpace( 1525 file_system->GetAvailableSpace(
1526 base::Bind(&GetSizeStatsFunction::GetDriveAvailableSpaceCallback, 1526 base::Bind(&GetSizeStatsFunction::GetDriveAvailableSpaceCallback,
1527 this)); 1527 this));
1528 1528
1529 } else { 1529 } else {
1530 BrowserThread::PostTask( 1530 BrowserThread::PostTask(
1531 BrowserThread::FILE, FROM_HERE, 1531 BrowserThread::FILE, FROM_HERE,
1532 base::Bind( 1532 base::Bind(
1533 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, 1533 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread,
1534 this, 1534 this,
1535 files[0].file_path.value())); 1535 files[0].file_path.value()));
1536 } 1536 }
1537 } 1537 }
1538 1538
1539 void GetSizeStatsFunction::GetDriveAvailableSpaceCallback( 1539 void GetSizeStatsFunction::GetDriveAvailableSpaceCallback(
1540 gdata::DriveFileError error, 1540 drive::DriveFileError error,
1541 int64 bytes_total, 1541 int64 bytes_total,
1542 int64 bytes_used) { 1542 int64 bytes_used) {
1543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1544 1544
1545 if (error == gdata::DRIVE_FILE_OK) { 1545 if (error == drive::DRIVE_FILE_OK) {
1546 int64 bytes_remaining = bytes_total - bytes_used; 1546 int64 bytes_remaining = bytes_total - bytes_used;
1547 GetSizeStatsCallbackOnUIThread(static_cast<size_t>(bytes_total/1024), 1547 GetSizeStatsCallbackOnUIThread(static_cast<size_t>(bytes_total/1024),
1548 static_cast<size_t>(bytes_remaining/1024)); 1548 static_cast<size_t>(bytes_remaining/1024));
1549 } else { 1549 } else {
1550 // If stats couldn't be gotten for drive, result should be left undefined. 1550 // If stats couldn't be gotten for drive, result should be left undefined.
1551 SendResponse(true); 1551 SendResponse(true);
1552 } 1552 }
1553 } 1553 }
1554 1554
1555 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( 1555 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread(
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 2018
2019 SET_STRING(IDS_FILE_BROWSER, ALL_FILES_FILTER); 2019 SET_STRING(IDS_FILE_BROWSER, ALL_FILES_FILTER);
2020 #undef SET_STRING 2020 #undef SET_STRING
2021 2021
2022 dict->SetBoolean("PDF_VIEW_ENABLED", 2022 dict->SetBoolean("PDF_VIEW_ENABLED",
2023 file_manager_util::ShouldBeOpenedWithPdfPlugin(profile(), ".pdf")); 2023 file_manager_util::ShouldBeOpenedWithPdfPlugin(profile(), ".pdf"));
2024 2024
2025 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); 2025 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict);
2026 2026
2027 dict->SetBoolean("ENABLE_GDATA", 2027 dict->SetBoolean("ENABLE_GDATA",
2028 gdata::DriveSystemService::IsDriveEnabled(profile())); 2028 drive::DriveSystemService::IsDriveEnabled(profile()));
2029 2029
2030 #if defined(USE_ASH) 2030 #if defined(USE_ASH)
2031 dict->SetBoolean("ASH", true); 2031 dict->SetBoolean("ASH", true);
2032 #else 2032 #else
2033 dict->SetBoolean("ASH", false); 2033 dict->SetBoolean("ASH", false);
2034 #endif 2034 #endif
2035 2035
2036 std::string board; 2036 std::string board;
2037 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; 2037 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD";
2038 chromeos::system::StatisticsProvider* provider = 2038 chromeos::system::StatisticsProvider* provider =
2039 chromeos::system::StatisticsProvider::GetInstance(); 2039 chromeos::system::StatisticsProvider::GetInstance();
2040 if (!provider->GetMachineStatistic(kMachineInfoBoard, &board)) 2040 if (!provider->GetMachineStatistic(kMachineInfoBoard, &board))
2041 board = "unknown"; 2041 board = "unknown";
2042 dict->SetString(kMachineInfoBoard, board); 2042 dict->SetString(kMachineInfoBoard, board);
2043 2043
2044 return true; 2044 return true;
2045 } 2045 }
2046 2046
2047 GetDriveFilePropertiesFunction::GetDriveFilePropertiesFunction() { 2047 GetDriveFilePropertiesFunction::GetDriveFilePropertiesFunction() {
2048 } 2048 }
2049 2049
2050 GetDriveFilePropertiesFunction::~GetDriveFilePropertiesFunction() { 2050 GetDriveFilePropertiesFunction::~GetDriveFilePropertiesFunction() {
2051 } 2051 }
2052 2052
2053 void GetDriveFilePropertiesFunction::DoOperation( 2053 void GetDriveFilePropertiesFunction::DoOperation(
2054 const FilePath& file_path, 2054 const FilePath& file_path,
2055 base::DictionaryValue* property_dict, 2055 base::DictionaryValue* property_dict,
2056 scoped_ptr<gdata::DriveEntryProto> entry_proto) { 2056 scoped_ptr<drive::DriveEntryProto> entry_proto) {
2057 DCHECK(property_dict); 2057 DCHECK(property_dict);
2058 2058
2059 // Nothing to do here so simply call OnOperationComplete(). 2059 // Nothing to do here so simply call OnOperationComplete().
2060 OnOperationComplete(file_path, 2060 OnOperationComplete(file_path,
2061 property_dict, 2061 property_dict,
2062 gdata::DRIVE_FILE_OK, 2062 drive::DRIVE_FILE_OK,
2063 entry_proto.Pass()); 2063 entry_proto.Pass());
2064 } 2064 }
2065 2065
2066 bool GetDriveFilePropertiesFunction::RunImpl() { 2066 bool GetDriveFilePropertiesFunction::RunImpl() {
2067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2068 if (args_->GetSize() != 1) 2068 if (args_->GetSize() != 1)
2069 return false; 2069 return false;
2070 2070
2071 PrepareResults(); 2071 PrepareResults();
2072 return true; 2072 return true;
(...skipping 20 matching lines...) Expand all
2093 std::string file_str; 2093 std::string file_str;
2094 path_list_->GetString(current_index_, &file_str); 2094 path_list_->GetString(current_index_, &file_str);
2095 GURL file_url = GURL(file_str); 2095 GURL file_url = GURL(file_str);
2096 FilePath file_path = GetVirtualPathFromURL(file_url); 2096 FilePath file_path = GetVirtualPathFromURL(file_url);
2097 2097
2098 base::DictionaryValue* property_dict = new base::DictionaryValue; 2098 base::DictionaryValue* property_dict = new base::DictionaryValue;
2099 property_dict->SetString("fileUrl", file_url.spec()); 2099 property_dict->SetString("fileUrl", file_url.spec());
2100 file_properties_->Append(property_dict); 2100 file_properties_->Append(property_dict);
2101 2101
2102 // Start getting the file info. 2102 // Start getting the file info.
2103 gdata::DriveSystemService* system_service = 2103 drive::DriveSystemService* system_service =
2104 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2104 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2105 system_service->file_system()->GetEntryInfoByPath( 2105 system_service->file_system()->GetEntryInfoByPath(
2106 file_path, 2106 file_path,
2107 base::Bind(&GetDriveFilePropertiesFunction::OnGetFileInfo, 2107 base::Bind(&GetDriveFilePropertiesFunction::OnGetFileInfo,
2108 this, 2108 this,
2109 file_path, 2109 file_path,
2110 property_dict)); 2110 property_dict));
2111 } 2111 }
2112 2112
2113 void GetDriveFilePropertiesFunction::CompleteGetFileProperties() { 2113 void GetDriveFilePropertiesFunction::CompleteGetFileProperties() {
2114 current_index_++; 2114 current_index_++;
2115 2115
2116 // Could be called from callback. Let finish operation. 2116 // Could be called from callback. Let finish operation.
2117 MessageLoop::current()->PostTask(FROM_HERE, 2117 MessageLoop::current()->PostTask(FROM_HERE,
2118 Bind(&GetDriveFilePropertiesFunction::GetNextFileProperties, this)); 2118 Bind(&GetDriveFilePropertiesFunction::GetNextFileProperties, this));
2119 } 2119 }
2120 2120
2121 void GetDriveFilePropertiesFunction::OnGetFileInfo( 2121 void GetDriveFilePropertiesFunction::OnGetFileInfo(
2122 const FilePath& file_path, 2122 const FilePath& file_path,
2123 base::DictionaryValue* property_dict, 2123 base::DictionaryValue* property_dict,
2124 gdata::DriveFileError error, 2124 drive::DriveFileError error,
2125 scoped_ptr<gdata::DriveEntryProto> entry_proto) { 2125 scoped_ptr<drive::DriveEntryProto> entry_proto) {
2126 DCHECK(property_dict); 2126 DCHECK(property_dict);
2127 2127
2128 if (entry_proto.get() && !entry_proto->has_file_specific_info()) 2128 if (entry_proto.get() && !entry_proto->has_file_specific_info())
2129 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND; 2129 error = drive::DRIVE_FILE_ERROR_NOT_FOUND;
2130 2130
2131 if (error == gdata::DRIVE_FILE_OK) 2131 if (error == drive::DRIVE_FILE_OK)
2132 DoOperation(file_path, property_dict, entry_proto.Pass()); 2132 DoOperation(file_path, property_dict, entry_proto.Pass());
2133 else 2133 else
2134 OnOperationComplete(file_path, property_dict, error, entry_proto.Pass()); 2134 OnOperationComplete(file_path, property_dict, error, entry_proto.Pass());
2135 } 2135 }
2136 2136
2137 void GetDriveFilePropertiesFunction::OnOperationComplete( 2137 void GetDriveFilePropertiesFunction::OnOperationComplete(
2138 const FilePath& file_path, 2138 const FilePath& file_path,
2139 base::DictionaryValue* property_dict, 2139 base::DictionaryValue* property_dict,
2140 gdata::DriveFileError error, 2140 drive::DriveFileError error,
2141 scoped_ptr<gdata::DriveEntryProto> entry_proto) { 2141 scoped_ptr<drive::DriveEntryProto> entry_proto) {
2142 if (entry_proto.get() && !entry_proto->has_file_specific_info()) 2142 if (entry_proto.get() && !entry_proto->has_file_specific_info())
2143 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND; 2143 error = drive::DRIVE_FILE_ERROR_NOT_FOUND;
2144 2144
2145 if (error != gdata::DRIVE_FILE_OK) { 2145 if (error != drive::DRIVE_FILE_OK) {
2146 property_dict->SetInteger("errorCode", error); 2146 property_dict->SetInteger("errorCode", error);
2147 CompleteGetFileProperties(); 2147 CompleteGetFileProperties();
2148 return; 2148 return;
2149 } 2149 }
2150 DCHECK(entry_proto.get()); 2150 DCHECK(entry_proto.get());
2151 2151
2152 const gdata::DriveFileSpecificInfo& file_specific_info = 2152 const drive::DriveFileSpecificInfo& file_specific_info =
2153 entry_proto->file_specific_info(); 2153 entry_proto->file_specific_info();
2154 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); 2154 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url());
2155 if (!file_specific_info.alternate_url().empty()) 2155 if (!file_specific_info.alternate_url().empty())
2156 property_dict->SetString("editUrl", file_specific_info.alternate_url()); 2156 property_dict->SetString("editUrl", file_specific_info.alternate_url());
2157 2157
2158 if (!entry_proto->content_url().empty()) { 2158 if (!entry_proto->content_url().empty()) {
2159 property_dict->SetString("contentUrl", entry_proto->content_url()); 2159 property_dict->SetString("contentUrl", entry_proto->content_url());
2160 } 2160 }
2161 2161
2162 property_dict->SetBoolean("isHosted", 2162 property_dict->SetBoolean("isHosted",
2163 file_specific_info.is_hosted_document()); 2163 file_specific_info.is_hosted_document());
2164 2164
2165 property_dict->SetString("contentMimeType", 2165 property_dict->SetString("contentMimeType",
2166 file_specific_info.content_mime_type()); 2166 file_specific_info.content_mime_type());
2167 2167
2168 gdata::DriveSystemService* system_service = 2168 drive::DriveSystemService* system_service =
2169 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2169 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2170 2170
2171 // Get drive WebApps that can accept this file. 2171 // Get drive WebApps that can accept this file.
2172 ScopedVector<gdata::DriveWebAppInfo> web_apps; 2172 ScopedVector<drive::DriveWebAppInfo> web_apps;
2173 system_service->webapps_registry()->GetWebAppsForFile( 2173 system_service->webapps_registry()->GetWebAppsForFile(
2174 file_path, file_specific_info.content_mime_type(), &web_apps); 2174 file_path, file_specific_info.content_mime_type(), &web_apps);
2175 if (!web_apps.empty()) { 2175 if (!web_apps.empty()) {
2176 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs( 2176 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs(
2177 profile_, 2177 profile_,
2178 file_specific_info.content_mime_type(), 2178 file_specific_info.content_mime_type(),
2179 file_path.Extension()); 2179 file_path.Extension());
2180 std::string default_app_id; 2180 std::string default_app_id;
2181 file_handler_util::CrackTaskID( 2181 file_handler_util::CrackTaskID(
2182 default_task_id, &default_app_id, NULL, NULL); 2182 default_task_id, &default_app_id, NULL, NULL);
2183 2183
2184 ListValue* apps = new ListValue(); 2184 ListValue* apps = new ListValue();
2185 property_dict->Set("driveApps", apps); 2185 property_dict->Set("driveApps", apps);
2186 for (ScopedVector<gdata::DriveWebAppInfo>::const_iterator it = 2186 for (ScopedVector<drive::DriveWebAppInfo>::const_iterator it =
2187 web_apps.begin(); 2187 web_apps.begin();
2188 it != web_apps.end(); ++it) { 2188 it != web_apps.end(); ++it) {
2189 const gdata::DriveWebAppInfo* webapp_info = *it; 2189 const drive::DriveWebAppInfo* webapp_info = *it;
2190 DictionaryValue* app = new DictionaryValue(); 2190 DictionaryValue* app = new DictionaryValue();
2191 app->SetString("appId", webapp_info->app_id); 2191 app->SetString("appId", webapp_info->app_id);
2192 app->SetString("appName", webapp_info->app_name); 2192 app->SetString("appName", webapp_info->app_name);
2193 GURL app_icon = FindPreferredIcon(webapp_info->app_icons, 2193 GURL app_icon = FindPreferredIcon(webapp_info->app_icons,
2194 kPreferredIconSize); 2194 kPreferredIconSize);
2195 if (!app_icon.is_empty()) 2195 if (!app_icon.is_empty())
2196 app->SetString("appIcon", app_icon.spec()); 2196 app->SetString("appIcon", app_icon.spec());
2197 GURL doc_icon = FindPreferredIcon(webapp_info->document_icons, 2197 GURL doc_icon = FindPreferredIcon(webapp_info->document_icons,
2198 kPreferredIconSize); 2198 kPreferredIconSize);
2199 if (!doc_icon.is_empty()) 2199 if (!doc_icon.is_empty())
(...skipping 18 matching lines...) Expand all
2218 entry_proto->resource_id(), 2218 entry_proto->resource_id(),
2219 file_specific_info.file_md5(), 2219 file_specific_info.file_md5(),
2220 base::Bind( 2220 base::Bind(
2221 &GetDriveFilePropertiesFunction::CacheStateReceived, 2221 &GetDriveFilePropertiesFunction::CacheStateReceived,
2222 this, property_dict)); 2222 this, property_dict));
2223 } 2223 }
2224 2224
2225 void GetDriveFilePropertiesFunction::CacheStateReceived( 2225 void GetDriveFilePropertiesFunction::CacheStateReceived(
2226 base::DictionaryValue* property_dict, 2226 base::DictionaryValue* property_dict,
2227 bool /* success */, 2227 bool /* success */,
2228 const gdata::DriveCacheEntry& cache_entry) { 2228 const drive::DriveCacheEntry& cache_entry) {
2229 // In case of an error (i.e. success is false), cache_entry.is_*() all 2229 // In case of an error (i.e. success is false), cache_entry.is_*() all
2230 // returns false. 2230 // returns false.
2231 property_dict->SetBoolean("isPinned", cache_entry.is_pinned()); 2231 property_dict->SetBoolean("isPinned", cache_entry.is_pinned());
2232 property_dict->SetBoolean("isPresent", cache_entry.is_present()); 2232 property_dict->SetBoolean("isPresent", cache_entry.is_present());
2233 property_dict->SetBoolean("isDirty", cache_entry.is_dirty()); 2233 property_dict->SetBoolean("isDirty", cache_entry.is_dirty());
2234 2234
2235 CompleteGetFileProperties(); 2235 CompleteGetFileProperties();
2236 } 2236 }
2237 2237
2238 PinDriveFileFunction::PinDriveFileFunction() { 2238 PinDriveFileFunction::PinDriveFileFunction() {
2239 } 2239 }
2240 2240
2241 PinDriveFileFunction::~PinDriveFileFunction() { 2241 PinDriveFileFunction::~PinDriveFileFunction() {
2242 } 2242 }
2243 2243
2244 bool PinDriveFileFunction::RunImpl() { 2244 bool PinDriveFileFunction::RunImpl() {
2245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2246 if (args_->GetSize() != 2 || !args_->GetBoolean(1, &set_pin_)) 2246 if (args_->GetSize() != 2 || !args_->GetBoolean(1, &set_pin_))
2247 return false; 2247 return false;
2248 2248
2249 PrepareResults(); 2249 PrepareResults();
2250 2250
2251 return true; 2251 return true;
2252 } 2252 }
2253 2253
2254 void PinDriveFileFunction::DoOperation( 2254 void PinDriveFileFunction::DoOperation(
2255 const FilePath& file_path, 2255 const FilePath& file_path,
2256 base::DictionaryValue* properties, 2256 base::DictionaryValue* properties,
2257 scoped_ptr<gdata::DriveEntryProto> entry_proto) { 2257 scoped_ptr<drive::DriveEntryProto> entry_proto) {
2258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2259 2259
2260 gdata::DriveSystemService* system_service = 2260 drive::DriveSystemService* system_service =
2261 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2261 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2262 // This is subtle but we should take references of resource_id and md5 2262 // This is subtle but we should take references of resource_id and md5
2263 // before |file_info| is passed to |callback| by base::Passed(). Otherwise, 2263 // before |file_info| is passed to |callback| by base::Passed(). Otherwise,
2264 // file_info->whatever() crashes. 2264 // file_info->whatever() crashes.
2265 const std::string& resource_id = entry_proto->resource_id(); 2265 const std::string& resource_id = entry_proto->resource_id();
2266 const std::string& md5 = entry_proto->file_specific_info().file_md5(); 2266 const std::string& md5 = entry_proto->file_specific_info().file_md5();
2267 const gdata::CacheOperationCallback callback = 2267 const drive::CacheOperationCallback callback =
2268 base::Bind(&PinDriveFileFunction::OnPinStateSet, 2268 base::Bind(&PinDriveFileFunction::OnPinStateSet,
2269 this, 2269 this,
2270 file_path, 2270 file_path,
2271 properties, 2271 properties,
2272 base::Passed(&entry_proto)); 2272 base::Passed(&entry_proto));
2273 2273
2274 if (set_pin_) 2274 if (set_pin_)
2275 system_service->cache()->PinOnUIThread(resource_id, md5, callback); 2275 system_service->cache()->PinOnUIThread(resource_id, md5, callback);
2276 else 2276 else
2277 system_service->cache()->UnpinOnUIThread(resource_id, md5, callback); 2277 system_service->cache()->UnpinOnUIThread(resource_id, md5, callback);
2278 } 2278 }
2279 2279
2280 void PinDriveFileFunction::OnPinStateSet( 2280 void PinDriveFileFunction::OnPinStateSet(
2281 const FilePath& path, 2281 const FilePath& path,
2282 base::DictionaryValue* properties, 2282 base::DictionaryValue* properties,
2283 scoped_ptr<gdata::DriveEntryProto> entry_proto, 2283 scoped_ptr<drive::DriveEntryProto> entry_proto,
2284 gdata::DriveFileError error, 2284 drive::DriveFileError error,
2285 const std::string& /* resource_id */, 2285 const std::string& /* resource_id */,
2286 const std::string& /* md5 */) { 2286 const std::string& /* md5 */) {
2287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2288 2288
2289 OnOperationComplete(path, properties, error, entry_proto.Pass()); 2289 OnOperationComplete(path, properties, error, entry_proto.Pass());
2290 } 2290 }
2291 2291
2292 GetFileLocationsFunction::GetFileLocationsFunction() { 2292 GetFileLocationsFunction::GetFileLocationsFunction() {
2293 } 2293 }
2294 2294
(...skipping 20 matching lines...) Expand all
2315 this)); 2315 this));
2316 return true; 2316 return true;
2317 } 2317 }
2318 2318
2319 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread( 2319 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread(
2320 const SelectedFileInfoList& files) { 2320 const SelectedFileInfoList& files) {
2321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2322 2322
2323 ListValue* locations = new ListValue; 2323 ListValue* locations = new ListValue;
2324 for (size_t i = 0; i < files.size(); ++i) { 2324 for (size_t i = 0; i < files.size(); ++i) {
2325 if (gdata::util::IsUnderDriveMountPoint(files[i].file_path)) { 2325 if (drive::util::IsUnderDriveMountPoint(files[i].file_path)) {
2326 locations->Append(Value::CreateStringValue("drive")); 2326 locations->Append(Value::CreateStringValue("drive"));
2327 } else { 2327 } else {
2328 locations->Append(Value::CreateStringValue("local")); 2328 locations->Append(Value::CreateStringValue("local"));
2329 } 2329 }
2330 } 2330 }
2331 2331
2332 SetResult(locations); 2332 SetResult(locations);
2333 SendResponse(true); 2333 SendResponse(true);
2334 } 2334 }
2335 2335
(...skipping 23 matching lines...) Expand all
2359 base::Bind(&GetDriveFilesFunction::GetLocalPathsResponseOnUIThread, 2359 base::Bind(&GetDriveFilesFunction::GetLocalPathsResponseOnUIThread,
2360 this)); 2360 this));
2361 return true; 2361 return true;
2362 } 2362 }
2363 2363
2364 void GetDriveFilesFunction::GetLocalPathsResponseOnUIThread( 2364 void GetDriveFilesFunction::GetLocalPathsResponseOnUIThread(
2365 const SelectedFileInfoList& files) { 2365 const SelectedFileInfoList& files) {
2366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2367 2367
2368 for (size_t i = 0; i < files.size(); ++i) { 2368 for (size_t i = 0; i < files.size(); ++i) {
2369 DCHECK(gdata::util::IsUnderDriveMountPoint(files[i].file_path)); 2369 DCHECK(drive::util::IsUnderDriveMountPoint(files[i].file_path));
2370 FilePath drive_path = gdata::util::ExtractDrivePath(files[i].file_path); 2370 FilePath drive_path = drive::util::ExtractDrivePath(files[i].file_path);
2371 remaining_drive_paths_.push(drive_path); 2371 remaining_drive_paths_.push(drive_path);
2372 } 2372 }
2373 2373
2374 local_paths_ = new ListValue; 2374 local_paths_ = new ListValue;
2375 GetFileOrSendResponse(); 2375 GetFileOrSendResponse();
2376 } 2376 }
2377 2377
2378 void GetDriveFilesFunction::GetFileOrSendResponse() { 2378 void GetDriveFilesFunction::GetFileOrSendResponse() {
2379 // Send the response if all files are obtained. 2379 // Send the response if all files are obtained.
2380 if (remaining_drive_paths_.empty()) { 2380 if (remaining_drive_paths_.empty()) {
2381 SetResult(local_paths_); 2381 SetResult(local_paths_);
2382 SendResponse(true); 2382 SendResponse(true);
2383 return; 2383 return;
2384 } 2384 }
2385 2385
2386 gdata::DriveSystemService* system_service = 2386 drive::DriveSystemService* system_service =
2387 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2387 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2388 DCHECK(system_service); 2388 DCHECK(system_service);
2389 2389
2390 // Get the file on the top of the queue. 2390 // Get the file on the top of the queue.
2391 FilePath drive_path = remaining_drive_paths_.front(); 2391 FilePath drive_path = remaining_drive_paths_.front();
2392 system_service->file_system()->GetFileByPath( 2392 system_service->file_system()->GetFileByPath(
2393 drive_path, 2393 drive_path,
2394 base::Bind(&GetDriveFilesFunction::OnFileReady, this), 2394 base::Bind(&GetDriveFilesFunction::OnFileReady, this),
2395 gdata::GetContentCallback()); 2395 gdata::GetContentCallback());
2396 } 2396 }
2397 2397
2398 2398
2399 void GetDriveFilesFunction::OnFileReady( 2399 void GetDriveFilesFunction::OnFileReady(
2400 gdata::DriveFileError error, 2400 drive::DriveFileError error,
2401 const FilePath& local_path, 2401 const FilePath& local_path,
2402 const std::string& unused_mime_type, 2402 const std::string& unused_mime_type,
2403 gdata::DriveFileType file_type) { 2403 drive::DriveFileType file_type) {
2404 FilePath drive_path = remaining_drive_paths_.front(); 2404 FilePath drive_path = remaining_drive_paths_.front();
2405 2405
2406 if (error == gdata::DRIVE_FILE_OK) { 2406 if (error == drive::DRIVE_FILE_OK) {
2407 local_paths_->Append(Value::CreateStringValue(local_path.value())); 2407 local_paths_->Append(Value::CreateStringValue(local_path.value()));
2408 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); 2408 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value();
2409 2409
2410 // TODO(benchan): If the file is a hosted document, a temporary JSON file 2410 // TODO(benchan): If the file is a hosted document, a temporary JSON file
2411 // is created to represent the document. The JSON file is not cached and 2411 // is created to represent the document. The JSON file is not cached and
2412 // should be deleted after use. We need to somehow communicate with 2412 // should be deleted after use. We need to somehow communicate with
2413 // file_manager.js to manage the lifetime of the temporary file. 2413 // file_manager.js to manage the lifetime of the temporary file.
2414 // See crosbug.com/28058. 2414 // See crosbug.com/28058.
2415 } else { 2415 } else {
2416 local_paths_->Append(Value::CreateStringValue("")); 2416 local_paths_->Append(Value::CreateStringValue(""));
2417 DVLOG(1) << "Failed to get " << drive_path.value() 2417 DVLOG(1) << "Failed to get " << drive_path.value()
2418 << " with error code: " << error; 2418 << " with error code: " << error;
2419 } 2419 }
2420 2420
2421 remaining_drive_paths_.pop(); 2421 remaining_drive_paths_.pop();
2422 2422
2423 // Start getting the next file. 2423 // Start getting the next file.
2424 GetFileOrSendResponse(); 2424 GetFileOrSendResponse();
2425 } 2425 }
2426 2426
2427 GetFileTransfersFunction::GetFileTransfersFunction() {} 2427 GetFileTransfersFunction::GetFileTransfersFunction() {}
2428 2428
2429 GetFileTransfersFunction::~GetFileTransfersFunction() {} 2429 GetFileTransfersFunction::~GetFileTransfersFunction() {}
2430 2430
2431 ListValue* GetFileTransfersFunction::GetFileTransfersList() { 2431 ListValue* GetFileTransfersFunction::GetFileTransfersList() {
2432 gdata::DriveSystemService* system_service = 2432 drive::DriveSystemService* system_service =
2433 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2433 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2434 if (!system_service) 2434 if (!system_service)
2435 return NULL; 2435 return NULL;
2436 2436
2437 gdata::OperationProgressStatusList list = 2437 gdata::OperationProgressStatusList list =
2438 system_service->drive_service()->GetProgressStatusList(); 2438 system_service->drive_service()->GetProgressStatusList();
2439 return file_manager_util::ProgressStatusVectorToListValue( 2439 return file_manager_util::ProgressStatusVectorToListValue(
2440 profile_, source_url_.GetOrigin(), list); 2440 profile_, source_url_.GetOrigin(), list);
2441 } 2441 }
2442 2442
2443 bool GetFileTransfersFunction::RunImpl() { 2443 bool GetFileTransfersFunction::RunImpl() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( 2476 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
2477 file_urls, 2477 file_urls,
2478 base::Bind(&CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread, 2478 base::Bind(&CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread,
2479 this)); 2479 this));
2480 return true; 2480 return true;
2481 } 2481 }
2482 2482
2483 void CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread( 2483 void CancelFileTransfersFunction::GetLocalPathsResponseOnUIThread(
2484 const SelectedFileInfoList& files) { 2484 const SelectedFileInfoList& files) {
2485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2486 gdata::DriveSystemService* system_service = 2486 drive::DriveSystemService* system_service =
2487 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2487 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2488 if (!system_service) { 2488 if (!system_service) {
2489 SendResponse(false); 2489 SendResponse(false);
2490 return; 2490 return;
2491 } 2491 }
2492 2492
2493 scoped_ptr<ListValue> responses(new ListValue()); 2493 scoped_ptr<ListValue> responses(new ListValue());
2494 for (size_t i = 0; i < files.size(); ++i) { 2494 for (size_t i = 0; i < files.size(); ++i) {
2495 DCHECK(gdata::util::IsUnderDriveMountPoint(files[i].file_path)); 2495 DCHECK(drive::util::IsUnderDriveMountPoint(files[i].file_path));
2496 FilePath file_path = gdata::util::ExtractDrivePath(files[i].file_path); 2496 FilePath file_path = drive::util::ExtractDrivePath(files[i].file_path);
2497 scoped_ptr<DictionaryValue> result(new DictionaryValue()); 2497 scoped_ptr<DictionaryValue> result(new DictionaryValue());
2498 result->SetBoolean( 2498 result->SetBoolean(
2499 "canceled", 2499 "canceled",
2500 system_service->drive_service()->CancelForFilePath(file_path)); 2500 system_service->drive_service()->CancelForFilePath(file_path));
2501 GURL file_url; 2501 GURL file_url;
2502 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, 2502 if (file_manager_util::ConvertFileToFileSystemUrl(profile_,
2503 gdata::util::GetSpecialRemoteRootPath().Append(file_path), 2503 drive::util::GetSpecialRemoteRootPath().Append(file_path),
2504 source_url_.GetOrigin(), 2504 source_url_.GetOrigin(),
2505 &file_url)) { 2505 &file_url)) {
2506 result->SetString("fileUrl", file_url.spec()); 2506 result->SetString("fileUrl", file_url.spec());
2507 } 2507 }
2508 2508
2509 responses->Append(result.release()); 2509 responses->Append(result.release());
2510 } 2510 }
2511 SetResult(responses.release()); 2511 SetResult(responses.release());
2512 SendResponse(true); 2512 SendResponse(true);
2513 } 2513 }
(...skipping 22 matching lines...) Expand all
2536 } 2536 }
2537 2537
2538 void TransferFileFunction::GetLocalPathsResponseOnUIThread( 2538 void TransferFileFunction::GetLocalPathsResponseOnUIThread(
2539 const SelectedFileInfoList& files) { 2539 const SelectedFileInfoList& files) {
2540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2541 if (files.size() != 2U) { 2541 if (files.size() != 2U) {
2542 SendResponse(false); 2542 SendResponse(false);
2543 return; 2543 return;
2544 } 2544 }
2545 2545
2546 gdata::DriveSystemService* system_service = 2546 drive::DriveSystemService* system_service =
2547 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2547 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2548 if (!system_service) { 2548 if (!system_service) {
2549 SendResponse(false); 2549 SendResponse(false);
2550 return; 2550 return;
2551 } 2551 }
2552 2552
2553 FilePath source_file = files[0].file_path; 2553 FilePath source_file = files[0].file_path;
2554 FilePath destination_file = files[1].file_path; 2554 FilePath destination_file = files[1].file_path;
2555 2555
2556 bool source_file_under_drive = 2556 bool source_file_under_drive =
2557 gdata::util::IsUnderDriveMountPoint(source_file); 2557 drive::util::IsUnderDriveMountPoint(source_file);
2558 bool destination_file_under_drive = 2558 bool destination_file_under_drive =
2559 gdata::util::IsUnderDriveMountPoint(destination_file); 2559 drive::util::IsUnderDriveMountPoint(destination_file);
2560 2560
2561 if (source_file_under_drive && !destination_file_under_drive) { 2561 if (source_file_under_drive && !destination_file_under_drive) {
2562 // Transfer a file from gdata to local file system. 2562 // Transfer a file from gdata to local file system.
2563 source_file = gdata::util::ExtractDrivePath(source_file); 2563 source_file = drive::util::ExtractDrivePath(source_file);
2564 system_service->file_system()->TransferFileFromRemoteToLocal( 2564 system_service->file_system()->TransferFileFromRemoteToLocal(
2565 source_file, 2565 source_file,
2566 destination_file, 2566 destination_file,
2567 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); 2567 base::Bind(&TransferFileFunction::OnTransferCompleted, this));
2568 } else if (!source_file_under_drive && destination_file_under_drive) { 2568 } else if (!source_file_under_drive && destination_file_under_drive) {
2569 // Transfer a file from local to Drive file system 2569 // Transfer a file from local to Drive file system
2570 destination_file = gdata::util::ExtractDrivePath(destination_file); 2570 destination_file = drive::util::ExtractDrivePath(destination_file);
2571 system_service->file_system()->TransferFileFromLocalToRemote( 2571 system_service->file_system()->TransferFileFromLocalToRemote(
2572 source_file, 2572 source_file,
2573 destination_file, 2573 destination_file,
2574 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); 2574 base::Bind(&TransferFileFunction::OnTransferCompleted, this));
2575 } else { 2575 } else {
2576 // Local-to-local or Drive-to-Drive file transfers should be done via 2576 // Local-to-local or Drive-to-Drive file transfers should be done via
2577 // FileEntry.copyTo in the File API and are thus not supported here. 2577 // FileEntry.copyTo in the File API and are thus not supported here.
2578 NOTREACHED(); 2578 NOTREACHED();
2579 SendResponse(false); 2579 SendResponse(false);
2580 } 2580 }
2581 } 2581 }
2582 2582
2583 void TransferFileFunction::OnTransferCompleted(gdata::DriveFileError error) { 2583 void TransferFileFunction::OnTransferCompleted(drive::DriveFileError error) {
2584 if (error == gdata::DRIVE_FILE_OK) { 2584 if (error == drive::DRIVE_FILE_OK) {
2585 SendResponse(true); 2585 SendResponse(true);
2586 } else { 2586 } else {
2587 error_ = base::StringPrintf("%d", static_cast<int>( 2587 error_ = base::StringPrintf("%d", static_cast<int>(
2588 fileapi::PlatformFileErrorToWebFileError( 2588 fileapi::PlatformFileErrorToWebFileError(
2589 gdata::DriveFileErrorToPlatformError(error)))); 2589 drive::DriveFileErrorToPlatformError(error))));
2590 SendResponse(false); 2590 SendResponse(false);
2591 } 2591 }
2592 } 2592 }
2593 2593
2594 // Read Drive-related preferences. 2594 // Read Drive-related preferences.
2595 bool GetDrivePreferencesFunction::RunImpl() { 2595 bool GetDrivePreferencesFunction::RunImpl() {
2596 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 2596 scoped_ptr<DictionaryValue> value(new DictionaryValue());
2597 2597
2598 const PrefService* service = profile_->GetPrefs(); 2598 const PrefService* service = profile_->GetPrefs();
2599 2599
2600 bool drive_enabled = gdata::DriveSystemService::IsDriveEnabled(profile_); 2600 bool drive_enabled = drive::DriveSystemService::IsDriveEnabled(profile_);
2601 2601
2602 if (drive_enabled) 2602 if (drive_enabled)
2603 AddDriveMountPoint(profile_, extension_id(), render_view_host()); 2603 AddDriveMountPoint(profile_, extension_id(), render_view_host());
2604 2604
2605 value->SetBoolean("driveEnabled", drive_enabled); 2605 value->SetBoolean("driveEnabled", drive_enabled);
2606 2606
2607 value->SetBoolean("cellularDisabled", 2607 value->SetBoolean("cellularDisabled",
2608 service->GetBoolean(prefs::kDisableGDataOverCellular)); 2608 service->GetBoolean(prefs::kDisableGDataOverCellular));
2609 2609
2610 value->SetBoolean("hostedFilesDisabled", 2610 value->SetBoolean("hostedFilesDisabled",
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2659 const std::string& file_system_name, 2659 const std::string& file_system_name,
2660 const GURL& file_system_url) { 2660 const GURL& file_system_url) {
2661 if (result != base::PLATFORM_FILE_OK) { 2661 if (result != base::PLATFORM_FILE_OK) {
2662 SendResponse(false); 2662 SendResponse(false);
2663 return; 2663 return;
2664 } 2664 }
2665 2665
2666 file_system_name_ = file_system_name; 2666 file_system_name_ = file_system_name;
2667 file_system_url_ = file_system_url; 2667 file_system_url_ = file_system_url;
2668 2668
2669 gdata::DriveSystemService* system_service = 2669 drive::DriveSystemService* system_service =
2670 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2670 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2671 if (!system_service || !system_service->file_system()) { 2671 if (!system_service || !system_service->file_system()) {
2672 SendResponse(false); 2672 SendResponse(false);
2673 return; 2673 return;
2674 } 2674 }
2675 2675
2676 system_service->file_system()->Search( 2676 system_service->file_system()->Search(
2677 query_, GURL(next_feed_), 2677 query_, GURL(next_feed_),
2678 base::Bind(&SearchDriveFunction::OnSearch, this)); 2678 base::Bind(&SearchDriveFunction::OnSearch, this));
2679 } 2679 }
2680 2680
2681 void SearchDriveFunction::OnSearch( 2681 void SearchDriveFunction::OnSearch(
2682 gdata::DriveFileError error, 2682 drive::DriveFileError error,
2683 const GURL& next_feed, 2683 const GURL& next_feed,
2684 scoped_ptr<std::vector<gdata::SearchResultInfo> > results) { 2684 scoped_ptr<std::vector<drive::SearchResultInfo> > results) {
2685 if (error != gdata::DRIVE_FILE_OK) { 2685 if (error != drive::DRIVE_FILE_OK) {
2686 SendResponse(false); 2686 SendResponse(false);
2687 return; 2687 return;
2688 } 2688 }
2689 2689
2690 DCHECK(results.get()); 2690 DCHECK(results.get());
2691 2691
2692 base::ListValue* entries = new ListValue(); 2692 base::ListValue* entries = new ListValue();
2693 // Convert Drive files to something File API stack can understand. 2693 // Convert Drive files to something File API stack can understand.
2694 for (size_t i = 0; i < results->size(); ++i) { 2694 for (size_t i = 0; i < results->size(); ++i) {
2695 DictionaryValue* entry = new DictionaryValue(); 2695 DictionaryValue* entry = new DictionaryValue();
2696 entry->SetString("fileSystemName", file_system_name_); 2696 entry->SetString("fileSystemName", file_system_name_);
2697 entry->SetString("fileSystemRoot", file_system_url_.spec()); 2697 entry->SetString("fileSystemRoot", file_system_url_.spec());
2698 entry->SetString("fileFullPath", "/" + results->at(i).path.value()); 2698 entry->SetString("fileFullPath", "/" + results->at(i).path.value());
2699 entry->SetBoolean("fileIsDirectory", results->at(i).is_directory); 2699 entry->SetBoolean("fileIsDirectory", results->at(i).is_directory);
2700 2700
2701 entries->Append(entry); 2701 entries->Append(entry);
2702 } 2702 }
2703 2703
2704 base::DictionaryValue* result = new DictionaryValue(); 2704 base::DictionaryValue* result = new DictionaryValue();
2705 result->Set("entries", entries); 2705 result->Set("entries", entries);
2706 result->SetString("nextFeed", next_feed.spec()); 2706 result->SetString("nextFeed", next_feed.spec());
2707 2707
2708 SetResult(result); 2708 SetResult(result);
2709 SendResponse(true); 2709 SendResponse(true);
2710 } 2710 }
2711 2711
2712 bool ClearDriveCacheFunction::RunImpl() { 2712 bool ClearDriveCacheFunction::RunImpl() {
2713 gdata::DriveSystemService* system_service = 2713 drive::DriveSystemService* system_service =
2714 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2714 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2715 // |system_service| is NULL if incognito window / guest login. 2715 // |system_service| is NULL if incognito window / guest login.
2716 if (!system_service || !system_service->file_system()) 2716 if (!system_service || !system_service->file_system())
2717 return false; 2717 return false;
2718 2718
2719 // TODO(yoshiki): Receive a callback from JS-side and pass it to 2719 // TODO(yoshiki): Receive a callback from JS-side and pass it to
2720 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511 2720 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511
2721 system_service->ClearCacheAndRemountFileSystem(base::Callback<void(bool)>()); 2721 system_service->ClearCacheAndRemountFileSystem(base::Callback<void(bool)>());
2722 2722
2723 SendResponse(true); 2723 SendResponse(true);
2724 return true; 2724 return true;
(...skipping 22 matching lines...) Expand all
2747 SetResult(value.release()); 2747 SetResult(value.release());
2748 2748
2749 return true; 2749 return true;
2750 } 2750 }
2751 2751
2752 bool RequestDirectoryRefreshFunction::RunImpl() { 2752 bool RequestDirectoryRefreshFunction::RunImpl() {
2753 std::string file_url_as_string; 2753 std::string file_url_as_string;
2754 if (!args_->GetString(0, &file_url_as_string)) 2754 if (!args_->GetString(0, &file_url_as_string))
2755 return false; 2755 return false;
2756 2756
2757 gdata::DriveSystemService* system_service = 2757 drive::DriveSystemService* system_service =
2758 gdata::DriveSystemServiceFactory::GetForProfile(profile_); 2758 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2759 if (!system_service || !system_service->file_system()) 2759 if (!system_service || !system_service->file_system())
2760 return false; 2760 return false;
2761 2761
2762 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); 2762 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string));
2763 system_service->file_system()->RequestDirectoryRefresh(directory_path); 2763 system_service->file_system()->RequestDirectoryRefresh(directory_path);
2764 2764
2765 return true; 2765 return true;
2766 } 2766 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.h ('k') | chrome/browser/chromeos/extensions/file_handler_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698