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

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

Issue 15814002: drive: Stop calling OpenFileSystem from SearchDriveFunction/SearchDriveMetadataFunction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_manager/file_browser_private_a pi.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a pi.h"
6 6
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <sys/statvfs.h> 8 #include <sys/statvfs.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <utime.h> 10 #include <utime.h>
(...skipping 2798 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 2809
2810 SearchDriveFunction::SearchDriveFunction() {} 2810 SearchDriveFunction::SearchDriveFunction() {}
2811 2811
2812 SearchDriveFunction::~SearchDriveFunction() {} 2812 SearchDriveFunction::~SearchDriveFunction() {}
2813 2813
2814 bool SearchDriveFunction::RunImpl() { 2814 bool SearchDriveFunction::RunImpl() {
2815 DictionaryValue* search_params; 2815 DictionaryValue* search_params;
2816 if (!args_->GetDictionary(0, &search_params)) 2816 if (!args_->GetDictionary(0, &search_params))
2817 return false; 2817 return false;
2818 2818
2819 if (!search_params->GetString("query", &query_)) 2819 std::string query;
2820 if (!search_params->GetString("query", &query))
2820 return false; 2821 return false;
2821 2822
2822 if (!search_params->GetString("nextFeed", &next_feed_)) 2823 std::string next_feed;
2824 if (!search_params->GetString("nextFeed", &next_feed))
2823 return false; 2825 return false;
2824 2826
2825 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance();
2826 BrowserContext::GetStoragePartition(profile(), site_instance)->
2827 GetFileSystemContext()->OpenFileSystem(
2828 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false,
2829 base::Bind(&SearchDriveFunction::OnFileSystemOpened, this));
2830 return true;
2831 }
2832
2833 void SearchDriveFunction::OnFileSystemOpened(
2834 base::PlatformFileError result,
2835 const std::string& file_system_name,
2836 const GURL& file_system_url) {
2837 if (result != base::PLATFORM_FILE_OK) {
2838 SendResponse(false);
2839 return;
2840 }
2841
2842 file_system_name_ = file_system_name;
2843 file_system_url_ = file_system_url;
2844
2845 drive::DriveIntegrationService* integration_service = 2827 drive::DriveIntegrationService* integration_service =
2846 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 2828 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
2847 // |integration_service| is NULL if Drive is disabled. 2829 // |integration_service| is NULL if Drive is disabled.
2848 if (!integration_service || !integration_service->file_system()) { 2830 if (!integration_service || !integration_service->file_system())
2849 SendResponse(false); 2831 return false;
2850 return;
2851 }
2852 2832
2853 integration_service->file_system()->Search( 2833 integration_service->file_system()->Search(
2854 query_, GURL(next_feed_), 2834 query, GURL(next_feed),
2855 base::Bind(&SearchDriveFunction::OnSearch, this)); 2835 base::Bind(&SearchDriveFunction::OnSearch, this));
2836 return true;
2856 } 2837 }
2857 2838
2858 void SearchDriveFunction::OnSearch( 2839 void SearchDriveFunction::OnSearch(
2859 drive::FileError error, 2840 drive::FileError error,
2860 const GURL& next_feed, 2841 const GURL& next_feed,
2861 scoped_ptr<std::vector<drive::SearchResultInfo> > results) { 2842 scoped_ptr<std::vector<drive::SearchResultInfo> > results) {
2862 if (error != drive::FILE_ERROR_OK) { 2843 if (error != drive::FILE_ERROR_OK) {
2863 SendResponse(false); 2844 SendResponse(false);
2864 return; 2845 return;
2865 } 2846 }
2866 2847
2867 DCHECK(results.get()); 2848 DCHECK(results.get());
2868 2849
2869 base::ListValue* entries = new ListValue(); 2850 base::ListValue* entries = new ListValue();
2870 2851
2871 // Convert Drive files to something File API stack can understand. 2852 // Convert Drive files to something File API stack can understand.
2853 GURL origin_url = source_url_.GetOrigin();
2854 fileapi::FileSystemType file_system_type = fileapi::kFileSystemTypeExternal;
2855 GURL file_system_root_url =
2856 fileapi::GetFileSystemRootURI(origin_url, file_system_type);
2857 std::string file_system_name =
2858 fileapi::GetFileSystemName(origin_url, file_system_type);
2872 for (size_t i = 0; i < results->size(); ++i) { 2859 for (size_t i = 0; i < results->size(); ++i) {
2873 DictionaryValue* entry = new DictionaryValue(); 2860 DictionaryValue* entry = new DictionaryValue();
2874 entry->SetString("fileSystemName", file_system_name_); 2861 entry->SetString("fileSystemName", file_system_name);
2875 entry->SetString("fileSystemRoot", file_system_url_.spec()); 2862 entry->SetString("fileSystemRoot", file_system_root_url.spec());
2876 entry->SetString("fileFullPath", "/" + results->at(i).path.value()); 2863 entry->SetString("fileFullPath", "/" + results->at(i).path.value());
2877 entry->SetBoolean("fileIsDirectory", 2864 entry->SetBoolean("fileIsDirectory",
2878 results->at(i).entry.file_info().is_directory()); 2865 results->at(i).entry.file_info().is_directory());
2879 entries->Append(entry); 2866 entries->Append(entry);
2880 } 2867 }
2881 2868
2882 base::DictionaryValue* result = new DictionaryValue(); 2869 base::DictionaryValue* result = new DictionaryValue();
2883 result->Set("entries", entries); 2870 result->Set("entries", entries);
2884 result->SetString("nextFeed", next_feed.spec()); 2871 result->SetString("nextFeed", next_feed.spec());
2885 2872
2886 SetResult(result); 2873 SetResult(result);
2887 SendResponse(true); 2874 SendResponse(true);
2888 } 2875 }
2889 2876
2890 SearchDriveMetadataFunction::SearchDriveMetadataFunction() 2877 SearchDriveMetadataFunction::SearchDriveMetadataFunction() {}
2891 : max_results_(0) {}
2892 2878
2893 SearchDriveMetadataFunction::~SearchDriveMetadataFunction() {} 2879 SearchDriveMetadataFunction::~SearchDriveMetadataFunction() {}
2894 2880
2895 bool SearchDriveMetadataFunction::RunImpl() { 2881 bool SearchDriveMetadataFunction::RunImpl() {
2896 DictionaryValue* search_params; 2882 DictionaryValue* search_params;
2897 if (!args_->GetDictionary(0, &search_params)) 2883 if (!args_->GetDictionary(0, &search_params))
2898 return false; 2884 return false;
2899 2885
2900 if (!search_params->GetString("query", &query_)) 2886 std::string query;
2887 if (!search_params->GetString("query", &query))
2901 return false; 2888 return false;
2902 2889
2903 if (!search_params->GetString("types", &types_)) 2890 std::string types;
2891 if (!search_params->GetString("types", &types))
2904 return false; 2892 return false;
2905 2893
2906 if (!search_params->GetInteger("maxResults", &max_results_)) 2894 int max_results = 0;
2895 if (!search_params->GetInteger("maxResults", &max_results))
2907 return false; 2896 return false;
2908 2897
2909 drive::util::Log("%s[%d] called. (types: '%s', maxResults: '%d')", 2898 drive::util::Log("%s[%d] called. (types: '%s', maxResults: '%d')",
2910 name().c_str(), 2899 name().c_str(),
2911 request_id(), 2900 request_id(),
2912 types_.c_str(), 2901 types.c_str(),
2913 max_results_); 2902 max_results);
2914 set_log_on_completion(true); 2903 set_log_on_completion(true);
2915 2904
2916 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance();
2917 BrowserContext::GetStoragePartition(profile(), site_instance)->
2918 GetFileSystemContext()->OpenFileSystem(
2919 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false,
2920 base::Bind(&SearchDriveMetadataFunction::OnFileSystemOpened, this));
2921 return true;
2922 }
2923
2924 void SearchDriveMetadataFunction::OnFileSystemOpened(
2925 base::PlatformFileError result,
2926 const std::string& file_system_name,
2927 const GURL& file_system_url) {
2928 if (result != base::PLATFORM_FILE_OK) {
2929 SendResponse(false);
2930 return;
2931 }
2932
2933 file_system_name_ = file_system_name;
2934 file_system_url_ = file_system_url;
2935
2936 drive::DriveIntegrationService* integration_service = 2905 drive::DriveIntegrationService* integration_service =
2937 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 2906 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
2938 // |integration_service| is NULL if Drive is disabled. 2907 // |integration_service| is NULL if Drive is disabled.
2939 if (!integration_service || !integration_service->file_system()) { 2908 if (!integration_service || !integration_service->file_system())
2940 SendResponse(false); 2909 return false;
2941 return;
2942 }
2943 2910
2944 int options = drive::SEARCH_METADATA_ALL; 2911 int options = drive::SEARCH_METADATA_ALL;
2945 // TODO(hirono): Switch to the JSON scheme compiler. http://crbug.com/241693 2912 // TODO(hirono): Switch to the JSON scheme compiler. http://crbug.com/241693
2946 if (types_ == "EXCLUDE_DIRECTORIES") 2913 if (types == "EXCLUDE_DIRECTORIES")
2947 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES; 2914 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES;
2948 else if (types_ == "SHARED_WITH_ME") 2915 else if (types == "SHARED_WITH_ME")
2949 options = drive::SEARCH_METADATA_SHARED_WITH_ME; 2916 options = drive::SEARCH_METADATA_SHARED_WITH_ME;
2950 else if (types_ == "OFFLINE") 2917 else if (types == "OFFLINE")
2951 options = drive::SEARCH_METADATA_OFFLINE; 2918 options = drive::SEARCH_METADATA_OFFLINE;
2952 else 2919 else
2953 DCHECK_EQ("ALL", types_); 2920 DCHECK_EQ("ALL", types);
2954 2921
2955 integration_service->file_system()->SearchMetadata( 2922 integration_service->file_system()->SearchMetadata(
2956 query_, 2923 query,
2957 options, 2924 options,
2958 max_results_, 2925 max_results,
2959 base::Bind(&SearchDriveMetadataFunction::OnSearchMetadata, this)); 2926 base::Bind(&SearchDriveMetadataFunction::OnSearchMetadata, this));
2927 return true;
2960 } 2928 }
2961 2929
2962 void SearchDriveMetadataFunction::OnSearchMetadata( 2930 void SearchDriveMetadataFunction::OnSearchMetadata(
2963 drive::FileError error, 2931 drive::FileError error,
2964 scoped_ptr<drive::MetadataSearchResultVector> results) { 2932 scoped_ptr<drive::MetadataSearchResultVector> results) {
2965 if (error != drive::FILE_ERROR_OK) { 2933 if (error != drive::FILE_ERROR_OK) {
2966 SendResponse(false); 2934 SendResponse(false);
2967 return; 2935 return;
2968 } 2936 }
2969 2937
2970 DCHECK(results.get()); 2938 DCHECK(results.get());
2971 2939
2972 base::ListValue* results_list = new ListValue(); 2940 base::ListValue* results_list = new ListValue();
2973 2941
2974 // Convert Drive files to something File API stack can understand. See 2942 // Convert Drive files to something File API stack can understand. See
2975 // file_browser_handler_custom_bindings.cc and 2943 // file_browser_handler_custom_bindings.cc and
2976 // file_browser_private_custom_bindings.js for how this is magically 2944 // file_browser_private_custom_bindings.js for how this is magically
2977 // converted to a FileEntry. 2945 // converted to a FileEntry.
2946 GURL origin_url = source_url_.GetOrigin();
2947 fileapi::FileSystemType file_system_type = fileapi::kFileSystemTypeExternal;
2948 GURL file_system_root_url =
2949 fileapi::GetFileSystemRootURI(origin_url, file_system_type);
2950 std::string file_system_name =
2951 fileapi::GetFileSystemName(origin_url, file_system_type);
2978 for (size_t i = 0; i < results->size(); ++i) { 2952 for (size_t i = 0; i < results->size(); ++i) {
2979 DictionaryValue* result_dict = new DictionaryValue(); 2953 DictionaryValue* result_dict = new DictionaryValue();
2980 2954
2981 // FileEntry fields. 2955 // FileEntry fields.
2982 DictionaryValue* entry = new DictionaryValue(); 2956 DictionaryValue* entry = new DictionaryValue();
2983 entry->SetString("fileSystemName", file_system_name_); 2957 entry->SetString("fileSystemName", file_system_name);
2984 entry->SetString("fileSystemRoot", file_system_url_.spec()); 2958 entry->SetString("fileSystemRoot", file_system_root_url.spec());
2985 entry->SetString("fileFullPath", "/" + results->at(i).path.value()); 2959 entry->SetString("fileFullPath", "/" + results->at(i).path.value());
2986 entry->SetBoolean("fileIsDirectory", 2960 entry->SetBoolean("fileIsDirectory",
2987 results->at(i).entry.file_info().is_directory()); 2961 results->at(i).entry.file_info().is_directory());
2988 2962
2989 result_dict->Set("entry", entry); 2963 result_dict->Set("entry", entry);
2990 result_dict->SetString("highlightedBaseName", 2964 result_dict->SetString("highlightedBaseName",
2991 results->at(i).highlighted_base_name); 2965 results->at(i).highlighted_base_name);
2992 results_list->Append(result_dict); 2966 results_list->Append(result_dict);
2993 } 2967 }
2994 2968
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 OpenNewWindowFunction::OpenNewWindowFunction() {} 3185 OpenNewWindowFunction::OpenNewWindowFunction() {}
3212 3186
3213 OpenNewWindowFunction::~OpenNewWindowFunction() {} 3187 OpenNewWindowFunction::~OpenNewWindowFunction() {}
3214 3188
3215 bool OpenNewWindowFunction::RunImpl() { 3189 bool OpenNewWindowFunction::RunImpl() {
3216 std::string url; 3190 std::string url;
3217 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); 3191 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
3218 file_manager_util::OpenNewWindow(profile_, GURL(url)); 3192 file_manager_util::OpenNewWindow(profile_, GURL(url));
3219 return true; 3193 return true;
3220 } 3194 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698