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

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

Issue 23715003: Files.app: Rename the FileBrowserPrivateAPI's functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the comments. 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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); 59 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url());
60 property_dict->SetBoolean("isHosted", 60 property_dict->SetBoolean("isHosted",
61 file_specific_info.is_hosted_document()); 61 file_specific_info.is_hosted_document());
62 property_dict->SetString("contentMimeType", 62 property_dict->SetString("contentMimeType",
63 file_specific_info.content_mime_type()); 63 file_specific_info.content_mime_type());
64 } 64 }
65 65
66 } // namespace 66 } // namespace
67 67
68 GetDriveEntryPropertiesFunction::GetDriveEntryPropertiesFunction() { 68 FileBrowserPrivateGetDriveEntryPropertiesFunction::
69 FileBrowserPrivateGetDriveEntryPropertiesFunction() {
69 } 70 }
70 71
71 GetDriveEntryPropertiesFunction::~GetDriveEntryPropertiesFunction() { 72 FileBrowserPrivateGetDriveEntryPropertiesFunction::
73 ~FileBrowserPrivateGetDriveEntryPropertiesFunction() {
72 } 74 }
73 75
74 bool GetDriveEntryPropertiesFunction::RunImpl() { 76 bool FileBrowserPrivateGetDriveEntryPropertiesFunction::RunImpl() {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 78
77 std::string file_url_str; 79 std::string file_url_str;
78 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) 80 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str))
79 return false; 81 return false;
80 82
81 GURL file_url = GURL(file_url_str); 83 GURL file_url = GURL(file_url_str);
82 file_path_ = drive::util::ExtractDrivePath( 84 file_path_ = drive::util::ExtractDrivePath(
83 file_manager::util::GetLocalPathFromURL( 85 file_manager::util::GetLocalPathFromURL(
84 render_view_host(), profile(), file_url)); 86 render_view_host(), profile(), file_url));
85 87
86 properties_.reset(new base::DictionaryValue); 88 properties_.reset(new base::DictionaryValue);
87 properties_->SetString("fileUrl", file_url.spec()); 89 properties_->SetString("fileUrl", file_url.spec());
88 90
89 // Start getting the file info. 91 // Start getting the file info.
90 drive::DriveIntegrationService* integration_service = 92 drive::DriveIntegrationService* integration_service =
91 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 93 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
92 // |integration_service| is NULL if Drive is disabled. 94 // |integration_service| is NULL if Drive is disabled.
93 if (!integration_service) { 95 if (!integration_service) {
94 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); 96 CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
95 return true; 97 return true;
96 } 98 }
97 99
98 integration_service->file_system()->GetResourceEntryByPath( 100 integration_service->file_system()->GetResourceEntryByPath(
99 file_path_, 101 file_path_,
100 base::Bind(&GetDriveEntryPropertiesFunction::OnGetFileInfo, this)); 102 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction::
103 OnGetFileInfo, this));
101 return true; 104 return true;
102 } 105 }
103 106
104 void GetDriveEntryPropertiesFunction::OnGetFileInfo( 107 void FileBrowserPrivateGetDriveEntryPropertiesFunction::OnGetFileInfo(
105 drive::FileError error, 108 drive::FileError error,
106 scoped_ptr<drive::ResourceEntry> entry) { 109 scoped_ptr<drive::ResourceEntry> entry) {
107 DCHECK(properties_); 110 DCHECK(properties_);
108 111
109 if (error != drive::FILE_ERROR_OK) { 112 if (error != drive::FILE_ERROR_OK) {
110 CompleteGetFileProperties(error); 113 CompleteGetFileProperties(error);
111 return; 114 return;
112 } 115 }
113 DCHECK(entry); 116 DCHECK(entry);
114 117
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const GURL doc_icon = 156 const GURL doc_icon =
154 drive::util::FindPreferredIcon(app_info->document_icons, 157 drive::util::FindPreferredIcon(app_info->document_icons,
155 drive::util::kPreferredIconSize); 158 drive::util::kPreferredIconSize);
156 properties_->SetString("customIconUrl", doc_icon.spec()); 159 properties_->SetString("customIconUrl", doc_icon.spec());
157 } 160 }
158 } 161 }
159 } 162 }
160 163
161 integration_service->file_system()->GetCacheEntryByPath( 164 integration_service->file_system()->GetCacheEntryByPath(
162 file_path_, 165 file_path_,
163 base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this)); 166 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction::
167 CacheStateReceived, this));
164 } 168 }
165 169
166 void GetDriveEntryPropertiesFunction::CacheStateReceived( 170 void FileBrowserPrivateGetDriveEntryPropertiesFunction::CacheStateReceived(
167 bool /* success */, 171 bool /* success */,
168 const drive::FileCacheEntry& cache_entry) { 172 const drive::FileCacheEntry& cache_entry) {
169 // In case of an error (i.e. success is false), cache_entry.is_*() all 173 // In case of an error (i.e. success is false), cache_entry.is_*() all
170 // returns false. 174 // returns false.
171 properties_->SetBoolean("isPinned", cache_entry.is_pinned()); 175 properties_->SetBoolean("isPinned", cache_entry.is_pinned());
172 properties_->SetBoolean("isPresent", cache_entry.is_present()); 176 properties_->SetBoolean("isPresent", cache_entry.is_present());
173 properties_->SetBoolean("isDirty", cache_entry.is_dirty()); 177 properties_->SetBoolean("isDirty", cache_entry.is_dirty());
174 178
175 CompleteGetFileProperties(drive::FILE_ERROR_OK); 179 CompleteGetFileProperties(drive::FILE_ERROR_OK);
176 } 180 }
177 181
178 void GetDriveEntryPropertiesFunction::CompleteGetFileProperties( 182 void FileBrowserPrivateGetDriveEntryPropertiesFunction::
179 drive::FileError error) { 183 CompleteGetFileProperties(drive::FileError error) {
180 if (error != drive::FILE_ERROR_OK) 184 if (error != drive::FILE_ERROR_OK)
181 properties_->SetInteger("errorCode", error); 185 properties_->SetInteger("errorCode", error);
182 SetResult(properties_.release()); 186 SetResult(properties_.release());
183 SendResponse(true); 187 SendResponse(true);
184 } 188 }
185 189
186 PinDriveFileFunction::PinDriveFileFunction() { 190 FileBrowserPrivatePinDriveFileFunction::
191 FileBrowserPrivatePinDriveFileFunction() {
187 } 192 }
188 193
189 PinDriveFileFunction::~PinDriveFileFunction() { 194 FileBrowserPrivatePinDriveFileFunction::
195 ~FileBrowserPrivatePinDriveFileFunction() {
190 } 196 }
191 197
192 bool PinDriveFileFunction::RunImpl() { 198 bool FileBrowserPrivatePinDriveFileFunction::RunImpl() {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 std::string url; 200 std::string url;
195 bool set_pin = false; 201 bool set_pin = false;
196 if (args_->GetSize() != 2 || 202 if (args_->GetSize() != 2 ||
197 !args_->GetString(0, &url) || 203 !args_->GetString(0, &url) ||
198 !args_->GetBoolean(1, &set_pin)) 204 !args_->GetBoolean(1, &set_pin))
199 return false; 205 return false;
200 206
201 drive::DriveIntegrationService* integration_service = 207 drive::DriveIntegrationService* integration_service =
202 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 208 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
203 drive::FileSystemInterface* file_system = 209 drive::FileSystemInterface* file_system =
204 integration_service ? integration_service->file_system() : NULL; 210 integration_service ? integration_service->file_system() : NULL;
205 if (!file_system) // |file_system| is NULL if Drive is disabled. 211 if (!file_system) // |file_system| is NULL if Drive is disabled.
206 return false; 212 return false;
207 213
208 base::FilePath drive_path = 214 base::FilePath drive_path =
209 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( 215 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL(
210 render_view_host(), profile(), GURL(url))); 216 render_view_host(), profile(), GURL(url)));
211 if (set_pin) { 217 if (set_pin) {
212 file_system->Pin(drive_path, 218 file_system->Pin(drive_path,
213 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); 219 base::Bind(&FileBrowserPrivatePinDriveFileFunction::
220 OnPinStateSet, this));
214 } else { 221 } else {
215 file_system->Unpin(drive_path, 222 file_system->Unpin(drive_path,
216 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); 223 base::Bind(&FileBrowserPrivatePinDriveFileFunction::
224 OnPinStateSet, this));
217 } 225 }
218 return true; 226 return true;
219 } 227 }
220 228
221 void PinDriveFileFunction::OnPinStateSet(drive::FileError error) { 229 void FileBrowserPrivatePinDriveFileFunction::
230 OnPinStateSet(drive::FileError error) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 232
224 if (error == drive::FILE_ERROR_OK) { 233 if (error == drive::FILE_ERROR_OK) {
225 SendResponse(true); 234 SendResponse(true);
226 } else { 235 } else {
227 error_ = drive::FileErrorToString(error); 236 error_ = drive::FileErrorToString(error);
228 SendResponse(false); 237 SendResponse(false);
229 } 238 }
230 } 239 }
231 240
232 GetDriveFilesFunction::GetDriveFilesFunction() 241 FileBrowserPrivateGetDriveFilesFunction::
233 : local_paths_(NULL) { 242 FileBrowserPrivateGetDriveFilesFunction() : local_paths_(NULL) {
234 } 243 }
235 244
236 GetDriveFilesFunction::~GetDriveFilesFunction() { 245 FileBrowserPrivateGetDriveFilesFunction::
246 ~FileBrowserPrivateGetDriveFilesFunction() {
237 } 247 }
238 248
239 bool GetDriveFilesFunction::RunImpl() { 249 bool FileBrowserPrivateGetDriveFilesFunction::RunImpl() {
240 ListValue* file_urls_as_strings = NULL; 250 ListValue* file_urls_as_strings = NULL;
241 if (!args_->GetList(0, &file_urls_as_strings)) 251 if (!args_->GetList(0, &file_urls_as_strings))
242 return false; 252 return false;
243 253
244 // Convert the list of strings to a list of GURLs. 254 // Convert the list of strings to a list of GURLs.
245 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { 255 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) {
246 std::string file_url_as_string; 256 std::string file_url_as_string;
247 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) 257 if (!file_urls_as_strings->GetString(i, &file_url_as_string))
248 return false; 258 return false;
249 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 259 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
250 render_view_host(), profile(), GURL(file_url_as_string)); 260 render_view_host(), profile(), GURL(file_url_as_string));
251 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 261 DCHECK(drive::util::IsUnderDriveMountPoint(path));
252 base::FilePath drive_path = drive::util::ExtractDrivePath(path); 262 base::FilePath drive_path = drive::util::ExtractDrivePath(path);
253 remaining_drive_paths_.push(drive_path); 263 remaining_drive_paths_.push(drive_path);
254 } 264 }
255 265
256 local_paths_ = new ListValue; 266 local_paths_ = new ListValue;
257 GetFileOrSendResponse(); 267 GetFileOrSendResponse();
258 return true; 268 return true;
259 } 269 }
260 270
261 void GetDriveFilesFunction::GetFileOrSendResponse() { 271 void FileBrowserPrivateGetDriveFilesFunction::GetFileOrSendResponse() {
262 // Send the response if all files are obtained. 272 // Send the response if all files are obtained.
263 if (remaining_drive_paths_.empty()) { 273 if (remaining_drive_paths_.empty()) {
264 SetResult(local_paths_); 274 SetResult(local_paths_);
265 SendResponse(true); 275 SendResponse(true);
266 return; 276 return;
267 } 277 }
268 278
269 // Get the file on the top of the queue. 279 // Get the file on the top of the queue.
270 base::FilePath drive_path = remaining_drive_paths_.front(); 280 base::FilePath drive_path = remaining_drive_paths_.front();
271 281
272 drive::DriveIntegrationService* integration_service = 282 drive::DriveIntegrationService* integration_service =
273 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 283 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
274 // |integration_service| is NULL if Drive is disabled. 284 // |integration_service| is NULL if Drive is disabled.
275 if (!integration_service) { 285 if (!integration_service) {
276 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, 286 OnFileReady(drive::FILE_ERROR_FAILED, drive_path,
277 scoped_ptr<drive::ResourceEntry>()); 287 scoped_ptr<drive::ResourceEntry>());
278 return; 288 return;
279 } 289 }
280 290
281 integration_service->file_system()->GetFileByPath( 291 integration_service->file_system()->GetFileByPath(
282 drive_path, 292 drive_path,
283 base::Bind(&GetDriveFilesFunction::OnFileReady, this)); 293 base::Bind(&FileBrowserPrivateGetDriveFilesFunction::OnFileReady, this));
284 } 294 }
285 295
286 296
287 void GetDriveFilesFunction::OnFileReady( 297 void FileBrowserPrivateGetDriveFilesFunction::OnFileReady(
288 drive::FileError error, 298 drive::FileError error,
289 const base::FilePath& local_path, 299 const base::FilePath& local_path,
290 scoped_ptr<drive::ResourceEntry> entry) { 300 scoped_ptr<drive::ResourceEntry> entry) {
291 base::FilePath drive_path = remaining_drive_paths_.front(); 301 base::FilePath drive_path = remaining_drive_paths_.front();
292 302
293 if (error == drive::FILE_ERROR_OK) { 303 if (error == drive::FILE_ERROR_OK) {
294 local_paths_->Append(new base::StringValue(local_path.value())); 304 local_paths_->Append(new base::StringValue(local_path.value()));
295 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); 305 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value();
296 306
297 // TODO(benchan): If the file is a hosted document, a temporary JSON file 307 // TODO(benchan): If the file is a hosted document, a temporary JSON file
298 // is created to represent the document. The JSON file is not cached and 308 // is created to represent the document. The JSON file is not cached and
299 // should be deleted after use. We need to somehow communicate with 309 // should be deleted after use. We need to somehow communicate with
300 // file_manager.js to manage the lifetime of the temporary file. 310 // file_manager.js to manage the lifetime of the temporary file.
301 // See crosbug.com/28058. 311 // See crosbug.com/28058.
302 } else { 312 } else {
303 local_paths_->Append(new base::StringValue("")); 313 local_paths_->Append(new base::StringValue(""));
304 DVLOG(1) << "Failed to get " << drive_path.value() 314 DVLOG(1) << "Failed to get " << drive_path.value()
305 << " with error code: " << error; 315 << " with error code: " << error;
306 } 316 }
307 317
308 remaining_drive_paths_.pop(); 318 remaining_drive_paths_.pop();
309 319
310 // Start getting the next file. 320 // Start getting the next file.
311 GetFileOrSendResponse(); 321 GetFileOrSendResponse();
312 } 322 }
313 323
314 CancelFileTransfersFunction::CancelFileTransfersFunction() { 324 FileBrowserPrivateCancelFileTransfersFunction::
325 FileBrowserPrivateCancelFileTransfersFunction() {
315 } 326 }
316 327
317 CancelFileTransfersFunction::~CancelFileTransfersFunction() { 328 FileBrowserPrivateCancelFileTransfersFunction::
329 ~FileBrowserPrivateCancelFileTransfersFunction() {
318 } 330 }
319 331
320 bool CancelFileTransfersFunction::RunImpl() { 332 bool FileBrowserPrivateCancelFileTransfersFunction::RunImpl() {
321 ListValue* url_list = NULL; 333 ListValue* url_list = NULL;
322 if (!args_->GetList(0, &url_list)) 334 if (!args_->GetList(0, &url_list))
323 return false; 335 return false;
324 336
325 drive::DriveIntegrationService* integration_service = 337 drive::DriveIntegrationService* integration_service =
326 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 338 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
327 // |integration_service| is NULL if Drive is disabled. 339 // |integration_service| is NULL if Drive is disabled.
328 if (!integration_service) 340 if (!integration_service)
329 return false; 341 return false;
330 342
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time, 377 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time,
366 // and eliminate this field; it is just returning a copy of the argument. 378 // and eliminate this field; it is just returning a copy of the argument.
367 result->SetString("fileUrl", url_as_string); 379 result->SetString("fileUrl", url_as_string);
368 responses->Append(result.release()); 380 responses->Append(result.release());
369 } 381 }
370 SetResult(responses.release()); 382 SetResult(responses.release());
371 SendResponse(true); 383 SendResponse(true);
372 return true; 384 return true;
373 } 385 }
374 386
375 SearchDriveFunction::SearchDriveFunction() { 387 FileBrowserPrivateSearchDriveFunction::
388 FileBrowserPrivateSearchDriveFunction() {
376 } 389 }
377 390
378 SearchDriveFunction::~SearchDriveFunction() { 391 FileBrowserPrivateSearchDriveFunction::
392 ~FileBrowserPrivateSearchDriveFunction() {
379 } 393 }
380 394
381 bool SearchDriveFunction::RunImpl() { 395 bool FileBrowserPrivateSearchDriveFunction::RunImpl() {
382 DictionaryValue* search_params; 396 DictionaryValue* search_params;
383 if (!args_->GetDictionary(0, &search_params)) 397 if (!args_->GetDictionary(0, &search_params))
384 return false; 398 return false;
385 399
386 std::string query; 400 std::string query;
387 if (!search_params->GetString("query", &query)) 401 if (!search_params->GetString("query", &query))
388 return false; 402 return false;
389 403
390 std::string next_feed; 404 std::string next_feed;
391 if (!search_params->GetString("nextFeed", &next_feed)) 405 if (!search_params->GetString("nextFeed", &next_feed))
392 return false; 406 return false;
393 407
394 drive::DriveIntegrationService* integration_service = 408 drive::DriveIntegrationService* integration_service =
395 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 409 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
396 // |integration_service| is NULL if Drive is disabled. 410 // |integration_service| is NULL if Drive is disabled.
397 if (!integration_service || !integration_service->file_system()) 411 if (!integration_service || !integration_service->file_system())
398 return false; 412 return false;
399 413
400 integration_service->file_system()->Search( 414 integration_service->file_system()->Search(
401 query, next_feed, 415 query, next_feed,
402 base::Bind(&SearchDriveFunction::OnSearch, this)); 416 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnSearch, this));
403 return true; 417 return true;
404 } 418 }
405 419
406 void SearchDriveFunction::OnSearch( 420 void FileBrowserPrivateSearchDriveFunction::OnSearch(
407 drive::FileError error, 421 drive::FileError error,
408 const std::string& next_feed, 422 const std::string& next_feed,
409 scoped_ptr<std::vector<drive::SearchResultInfo> > results) { 423 scoped_ptr<std::vector<drive::SearchResultInfo> > results) {
410 if (error != drive::FILE_ERROR_OK) { 424 if (error != drive::FILE_ERROR_OK) {
411 SendResponse(false); 425 SendResponse(false);
412 return; 426 return;
413 } 427 }
414 428
415 DCHECK(results.get()); 429 DCHECK(results.get());
416 430
(...skipping 17 matching lines...) Expand all
434 } 448 }
435 449
436 base::DictionaryValue* result = new DictionaryValue(); 450 base::DictionaryValue* result = new DictionaryValue();
437 result->Set("entries", entries); 451 result->Set("entries", entries);
438 result->SetString("nextFeed", next_feed); 452 result->SetString("nextFeed", next_feed);
439 453
440 SetResult(result); 454 SetResult(result);
441 SendResponse(true); 455 SendResponse(true);
442 } 456 }
443 457
444 SearchDriveMetadataFunction::SearchDriveMetadataFunction() { 458 FileBrowserPrivateSearchDriveMetadataFunction::
459 FileBrowserPrivateSearchDriveMetadataFunction() {
445 } 460 }
446 461
447 SearchDriveMetadataFunction::~SearchDriveMetadataFunction() { 462 FileBrowserPrivateSearchDriveMetadataFunction::
463 ~FileBrowserPrivateSearchDriveMetadataFunction() {
448 } 464 }
449 465
450 bool SearchDriveMetadataFunction::RunImpl() { 466 bool FileBrowserPrivateSearchDriveMetadataFunction::RunImpl() {
451 DictionaryValue* search_params; 467 DictionaryValue* search_params;
452 if (!args_->GetDictionary(0, &search_params)) 468 if (!args_->GetDictionary(0, &search_params))
453 return false; 469 return false;
454 470
455 std::string query; 471 std::string query;
456 if (!search_params->GetString("query", &query)) 472 if (!search_params->GetString("query", &query))
457 return false; 473 return false;
458 474
459 std::string types; 475 std::string types;
460 if (!search_params->GetString("types", &types)) 476 if (!search_params->GetString("types", &types))
(...skipping 25 matching lines...) Expand all
486 options = drive::SEARCH_METADATA_SHARED_WITH_ME; 502 options = drive::SEARCH_METADATA_SHARED_WITH_ME;
487 else if (types == "OFFLINE") 503 else if (types == "OFFLINE")
488 options = drive::SEARCH_METADATA_OFFLINE; 504 options = drive::SEARCH_METADATA_OFFLINE;
489 else 505 else
490 DCHECK_EQ("ALL", types); 506 DCHECK_EQ("ALL", types);
491 507
492 integration_service->file_system()->SearchMetadata( 508 integration_service->file_system()->SearchMetadata(
493 query, 509 query,
494 options, 510 options,
495 max_results, 511 max_results,
496 base::Bind(&SearchDriveMetadataFunction::OnSearchMetadata, this)); 512 base::Bind(&FileBrowserPrivateSearchDriveMetadataFunction::
513 OnSearchMetadata, this));
497 return true; 514 return true;
498 } 515 }
499 516
500 void SearchDriveMetadataFunction::OnSearchMetadata( 517 void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata(
501 drive::FileError error, 518 drive::FileError error,
502 scoped_ptr<drive::MetadataSearchResultVector> results) { 519 scoped_ptr<drive::MetadataSearchResultVector> results) {
503 if (error != drive::FILE_ERROR_OK) { 520 if (error != drive::FILE_ERROR_OK) {
504 SendResponse(false); 521 SendResponse(false);
505 return; 522 return;
506 } 523 }
507 524
508 DCHECK(results.get()); 525 DCHECK(results.get());
509 526
510 base::ListValue* results_list = new ListValue(); 527 base::ListValue* results_list = new ListValue();
(...skipping 22 matching lines...) Expand all
533 result_dict->Set("entry", entry); 550 result_dict->Set("entry", entry);
534 result_dict->SetString("highlightedBaseName", 551 result_dict->SetString("highlightedBaseName",
535 results->at(i).highlighted_base_name); 552 results->at(i).highlighted_base_name);
536 results_list->Append(result_dict); 553 results_list->Append(result_dict);
537 } 554 }
538 555
539 SetResult(results_list); 556 SetResult(results_list);
540 SendResponse(true); 557 SendResponse(true);
541 } 558 }
542 559
543 ClearDriveCacheFunction::ClearDriveCacheFunction() { 560 FileBrowserPrivateClearDriveCacheFunction::
561 FileBrowserPrivateClearDriveCacheFunction() {
544 } 562 }
545 563
546 ClearDriveCacheFunction::~ClearDriveCacheFunction() { 564 FileBrowserPrivateClearDriveCacheFunction::
565 ~FileBrowserPrivateClearDriveCacheFunction() {
547 } 566 }
548 567
549 bool ClearDriveCacheFunction::RunImpl() { 568 bool FileBrowserPrivateClearDriveCacheFunction::RunImpl() {
550 drive::DriveIntegrationService* integration_service = 569 drive::DriveIntegrationService* integration_service =
551 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 570 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
552 // |integration_service| is NULL if Drive is disabled. 571 // |integration_service| is NULL if Drive is disabled.
553 if (!integration_service || !integration_service->file_system()) 572 if (!integration_service || !integration_service->file_system())
554 return false; 573 return false;
555 574
556 // TODO(yoshiki): Receive a callback from JS-side and pass it to 575 // TODO(yoshiki): Receive a callback from JS-side and pass it to
557 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511 576 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511
558 integration_service->ClearCacheAndRemountFileSystem( 577 integration_service->ClearCacheAndRemountFileSystem(
559 base::Bind(&DoNothingWithBool)); 578 base::Bind(&DoNothingWithBool));
560 579
561 SendResponse(true); 580 SendResponse(true);
562 return true; 581 return true;
563 } 582 }
564 583
565 GetDriveConnectionStateFunction::GetDriveConnectionStateFunction() { 584 FileBrowserPrivateGetDriveConnectionStateFunction::
585 FileBrowserPrivateGetDriveConnectionStateFunction() {
566 } 586 }
567 587
568 GetDriveConnectionStateFunction::~GetDriveConnectionStateFunction() { 588 FileBrowserPrivateGetDriveConnectionStateFunction::
589 ~FileBrowserPrivateGetDriveConnectionStateFunction() {
569 } 590 }
570 591
571 bool GetDriveConnectionStateFunction::RunImpl() { 592 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() {
572 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 593 scoped_ptr<DictionaryValue> value(new DictionaryValue());
573 scoped_ptr<ListValue> reasons(new ListValue()); 594 scoped_ptr<ListValue> reasons(new ListValue());
574 595
575 std::string type_string; 596 std::string type_string;
576 drive::DriveIntegrationService* integration_service = 597 drive::DriveIntegrationService* integration_service =
577 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 598 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
578 599
579 bool ready = integration_service && 600 bool ready = integration_service &&
580 integration_service->drive_service()->CanSendRequest(); 601 integration_service->drive_service()->CanSendRequest();
581 bool is_connection_cellular = 602 bool is_connection_cellular =
(...skipping 17 matching lines...) Expand all
599 } 620 }
600 621
601 value->SetString("type", type_string); 622 value->SetString("type", type_string);
602 value->Set("reasons", reasons.release()); 623 value->Set("reasons", reasons.release());
603 SetResult(value.release()); 624 SetResult(value.release());
604 625
605 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); 626 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str());
606 return true; 627 return true;
607 } 628 }
608 629
609 RequestAccessTokenFunction::RequestAccessTokenFunction() { 630 FileBrowserPrivateRequestAccessTokenFunction::
631 FileBrowserPrivateRequestAccessTokenFunction() {
610 } 632 }
611 633
612 RequestAccessTokenFunction::~RequestAccessTokenFunction() { 634 FileBrowserPrivateRequestAccessTokenFunction::
635 ~FileBrowserPrivateRequestAccessTokenFunction() {
613 } 636 }
614 637
615 bool RequestAccessTokenFunction::RunImpl() { 638 bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() {
616 drive::DriveIntegrationService* integration_service = 639 drive::DriveIntegrationService* integration_service =
617 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 640 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
618 bool refresh; 641 bool refresh;
619 args_->GetBoolean(0, &refresh); 642 args_->GetBoolean(0, &refresh);
620 643
621 if (!integration_service) { 644 if (!integration_service) {
622 SetResult(new base::StringValue("")); 645 SetResult(new base::StringValue(""));
623 SendResponse(true); 646 SendResponse(true);
624 return true; 647 return true;
625 } 648 }
626 649
627 // If refreshing is requested, then clear the token to refetch it. 650 // If refreshing is requested, then clear the token to refetch it.
628 if (refresh) 651 if (refresh)
629 integration_service->drive_service()->ClearAccessToken(); 652 integration_service->drive_service()->ClearAccessToken();
630 653
631 // Retrieve the cached auth token (if available), otherwise the AuthService 654 // Retrieve the cached auth token (if available), otherwise the AuthService
632 // instance will try to refetch it. 655 // instance will try to refetch it.
633 integration_service->drive_service()->RequestAccessToken( 656 integration_service->drive_service()->RequestAccessToken(
634 base::Bind(&RequestAccessTokenFunction::OnAccessTokenFetched, this)); 657 base::Bind(&FileBrowserPrivateRequestAccessTokenFunction::
658 OnAccessTokenFetched, this));
635 return true; 659 return true;
636 } 660 }
637 661
638 void RequestAccessTokenFunction::OnAccessTokenFetched( 662 void FileBrowserPrivateRequestAccessTokenFunction::OnAccessTokenFetched(
639 google_apis::GDataErrorCode code, const std::string& access_token) { 663 google_apis::GDataErrorCode code,
664 const std::string& access_token) {
640 SetResult(new base::StringValue(access_token)); 665 SetResult(new base::StringValue(access_token));
641 SendResponse(true); 666 SendResponse(true);
642 } 667 }
643 668
644 GetShareUrlFunction::GetShareUrlFunction() { 669 FileBrowserPrivateGetShareUrlFunction::FileBrowserPrivateGetShareUrlFunction() {
645 } 670 }
646 671
647 GetShareUrlFunction::~GetShareUrlFunction() { 672 FileBrowserPrivateGetShareUrlFunction::
673 ~FileBrowserPrivateGetShareUrlFunction() {
648 } 674 }
649 675
650 bool GetShareUrlFunction::RunImpl() { 676 bool FileBrowserPrivateGetShareUrlFunction::RunImpl() {
651 std::string file_url; 677 std::string file_url;
652 if (!args_->GetString(0, &file_url)) 678 if (!args_->GetString(0, &file_url))
653 return false; 679 return false;
654 680
655 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 681 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
656 render_view_host(), profile(), GURL(file_url)); 682 render_view_host(), profile(), GURL(file_url));
657 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 683 DCHECK(drive::util::IsUnderDriveMountPoint(path));
658 684
659 base::FilePath drive_path = drive::util::ExtractDrivePath(path); 685 base::FilePath drive_path = drive::util::ExtractDrivePath(path);
660 686
661 drive::DriveIntegrationService* integration_service = 687 drive::DriveIntegrationService* integration_service =
662 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 688 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
663 // |integration_service| is NULL if Drive is disabled. 689 // |integration_service| is NULL if Drive is disabled.
664 if (!integration_service) 690 if (!integration_service)
665 return false; 691 return false;
666 692
667 integration_service->file_system()->GetShareUrl( 693 integration_service->file_system()->GetShareUrl(
668 drive_path, 694 drive_path,
669 file_manager::util::GetFileManagerBaseUrl(), // embed origin 695 file_manager::util::GetFileManagerBaseUrl(), // embed origin
670 base::Bind(&GetShareUrlFunction::OnGetShareUrl, this)); 696 base::Bind(&FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl, this));
671 return true; 697 return true;
672 } 698 }
673 699
674 700
675 void GetShareUrlFunction::OnGetShareUrl(drive::FileError error, 701 void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl(
676 const GURL& share_url) { 702 drive::FileError error,
703 const GURL& share_url) {
677 if (error != drive::FILE_ERROR_OK) { 704 if (error != drive::FILE_ERROR_OK) {
678 error_ = "Share Url for this item is not available."; 705 error_ = "Share Url for this item is not available.";
679 SendResponse(false); 706 SendResponse(false);
680 return; 707 return;
681 } 708 }
682 709
683 SetResult(new base::StringValue(share_url.spec())); 710 SetResult(new base::StringValue(share_url.spec()));
684 SendResponse(true); 711 SendResponse(true);
685 } 712 }
686 713
687 } // namespace extensions 714 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698