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

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

Issue 23581006: Reland 220012: Move the functions of filebrowserPrivateApi from the file_manager namespace to the e… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_file_syste m.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste m.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 25 matching lines...) Expand all
36 #include "webkit/common/fileapi/file_system_types.h" 36 #include "webkit/common/fileapi/file_system_types.h"
37 #include "webkit/common/fileapi/file_system_util.h" 37 #include "webkit/common/fileapi/file_system_util.h"
38 38
39 using chromeos::disks::DiskMountManager; 39 using chromeos::disks::DiskMountManager;
40 using content::BrowserContext; 40 using content::BrowserContext;
41 using content::BrowserThread; 41 using content::BrowserThread;
42 using content::ChildProcessSecurityPolicy; 42 using content::ChildProcessSecurityPolicy;
43 using content::WebContents; 43 using content::WebContents;
44 using fileapi::FileSystemURL; 44 using fileapi::FileSystemURL;
45 45
46 namespace file_manager { 46 namespace extensions {
47 namespace { 47 namespace {
48 48
49 // Error messages. 49 // Error messages.
50 const char kFileError[] = "File error %d"; 50 const char kFileError[] = "File error %d";
51 51
52 const DiskMountManager::Disk* GetVolumeAsDisk(const std::string& mount_path) { 52 const DiskMountManager::Disk* GetVolumeAsDisk(const std::string& mount_path) {
53 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 53 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
54 54
55 DiskMountManager::MountPointMap::const_iterator mount_point_it = 55 DiskMountManager::MountPointMap::const_iterator mount_point_it =
56 disk_mount_manager->mount_points().find(mount_path); 56 disk_mount_manager->mount_points().find(mount_path);
57 if (mount_point_it == disk_mount_manager->mount_points().end()) 57 if (mount_point_it == disk_mount_manager->mount_points().end())
58 return NULL; 58 return NULL;
59 59
60 const DiskMountManager::Disk* disk = disk_mount_manager->FindDiskBySourcePath( 60 const DiskMountManager::Disk* disk = disk_mount_manager->FindDiskBySourcePath(
61 mount_point_it->second.source_path); 61 mount_point_it->second.source_path);
62 62
63 return (disk && disk->is_hidden()) ? NULL : disk; 63 return (disk && disk->is_hidden()) ? NULL : disk;
64 } 64 }
65 65
66 base::DictionaryValue* CreateValueFromDisk( 66 base::DictionaryValue* CreateValueFromDisk(
67 Profile* profile, 67 Profile* profile,
68 const std::string& extension_id, 68 const std::string& extension_id,
69 const DiskMountManager::Disk* volume) { 69 const DiskMountManager::Disk* volume) {
70 base::DictionaryValue* volume_info = new base::DictionaryValue(); 70 base::DictionaryValue* volume_info = new base::DictionaryValue();
71 71
72 std::string mount_path; 72 std::string mount_path;
73 if (!volume->mount_path().empty()) { 73 if (!volume->mount_path().empty()) {
74 base::FilePath relative_mount_path; 74 base::FilePath relative_mount_path;
75 util::ConvertAbsoluteFilePathToRelativeFileSystemPath( 75 file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
76 profile, extension_id, base::FilePath(volume->mount_path()), 76 profile, extension_id, base::FilePath(volume->mount_path()),
77 &relative_mount_path); 77 &relative_mount_path);
78 mount_path = relative_mount_path.value(); 78 mount_path = relative_mount_path.value();
79 } 79 }
80 80
81 volume_info->SetString("devicePath", volume->device_path()); 81 volume_info->SetString("devicePath", volume->device_path());
82 volume_info->SetString("mountPath", mount_path); 82 volume_info->SetString("mountPath", mount_path);
83 volume_info->SetString("systemPath", volume->system_path()); 83 volume_info->SetString("systemPath", volume->system_path());
84 volume_info->SetString("filePath", volume->file_path()); 84 volume_info->SetString("filePath", volume->file_path());
85 volume_info->SetString("deviceLabel", volume->device_label()); 85 volume_info->SetString("deviceLabel", volume->device_label());
(...skipping 17 matching lines...) Expand all
103 void SetDriveMountPointPermissions( 103 void SetDriveMountPointPermissions(
104 Profile* profile, 104 Profile* profile,
105 const std::string& extension_id, 105 const std::string& extension_id,
106 content::RenderViewHost* render_view_host) { 106 content::RenderViewHost* render_view_host) {
107 if (!render_view_host || 107 if (!render_view_host ||
108 !render_view_host->GetSiteInstance() || !render_view_host->GetProcess()) { 108 !render_view_host->GetSiteInstance() || !render_view_host->GetProcess()) {
109 return; 109 return;
110 } 110 }
111 111
112 fileapi::ExternalFileSystemBackend* backend = 112 fileapi::ExternalFileSystemBackend* backend =
113 util::GetFileSystemContextForRenderViewHost( 113 file_manager::util::GetFileSystemContextForRenderViewHost(
114 profile, render_view_host)->external_backend(); 114 profile, render_view_host)->external_backend();
115 if (!backend) 115 if (!backend)
116 return; 116 return;
117 117
118 const base::FilePath mount_point = drive::util::GetDriveMountPointPath(); 118 const base::FilePath mount_point = drive::util::GetDriveMountPointPath();
119 // Grant R/W permissions to drive 'folder'. File API layer still 119 // Grant R/W permissions to drive 'folder'. File API layer still
120 // expects this to be satisfied. 120 // expects this to be satisfied.
121 ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile( 121 ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile(
122 render_view_host->GetProcess()->GetID(), mount_point); 122 render_view_host->GetProcess()->GetID(), mount_point);
123 123
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 bool RequestFileSystemFunction::RunImpl() { 266 bool RequestFileSystemFunction::RunImpl() {
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
268 268
269 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess()) 269 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess())
270 return false; 270 return false;
271 271
272 set_log_on_completion(true); 272 set_log_on_completion(true);
273 273
274 scoped_refptr<fileapi::FileSystemContext> file_system_context = 274 scoped_refptr<fileapi::FileSystemContext> file_system_context =
275 util::GetFileSystemContextForRenderViewHost( 275 file_manager::util::GetFileSystemContextForRenderViewHost(
276 profile(), render_view_host()); 276 profile(), render_view_host());
277 277
278 const GURL origin_url = source_url_.GetOrigin(); 278 const GURL origin_url = source_url_.GetOrigin();
279 file_system_context->OpenFileSystem( 279 file_system_context->OpenFileSystem(
280 origin_url, 280 origin_url,
281 fileapi::kFileSystemTypeExternal, 281 fileapi::kFileSystemTypeExternal,
282 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, 282 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
283 base::Bind(&RequestFileSystemFunction::DidOpenFileSystem, 283 base::Bind(&RequestFileSystemFunction::DidOpenFileSystem,
284 this, 284 this,
285 file_system_context)); 285 file_system_context));
(...skipping 18 matching lines...) Expand all
304 304
305 if (!render_view_host() || !render_view_host()->GetProcess()) 305 if (!render_view_host() || !render_view_host()->GetProcess())
306 return false; 306 return false;
307 307
308 // First param is url of a file to watch. 308 // First param is url of a file to watch.
309 std::string url; 309 std::string url;
310 if (!args_->GetString(0, &url) || url.empty()) 310 if (!args_->GetString(0, &url) || url.empty())
311 return false; 311 return false;
312 312
313 scoped_refptr<fileapi::FileSystemContext> file_system_context = 313 scoped_refptr<fileapi::FileSystemContext> file_system_context =
314 util::GetFileSystemContextForRenderViewHost( 314 file_manager::util::GetFileSystemContextForRenderViewHost(
315 profile(), render_view_host()); 315 profile(), render_view_host());
316 316
317 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); 317 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url));
318 base::FilePath local_path = file_watch_url.path(); 318 base::FilePath local_path = file_watch_url.path();
319 base::FilePath virtual_path = file_watch_url.virtual_path(); 319 base::FilePath virtual_path = file_watch_url.virtual_path();
320 if (local_path.empty()) { 320 if (local_path.empty()) {
321 Respond(false); 321 Respond(false);
322 return true; 322 return true;
323 } 323 }
324 PerformFileWatchOperation(local_path, virtual_path, extension_id()); 324 PerformFileWatchOperation(local_path, virtual_path, extension_id());
325 325
326 return true; 326 return true;
327 } 327 }
328 328
329 AddFileWatchFunction::AddFileWatchFunction() { 329 AddFileWatchFunction::AddFileWatchFunction() {
330 } 330 }
331 331
332 AddFileWatchFunction::~AddFileWatchFunction() { 332 AddFileWatchFunction::~AddFileWatchFunction() {
333 } 333 }
334 334
335 void AddFileWatchFunction::PerformFileWatchOperation( 335 void AddFileWatchFunction::PerformFileWatchOperation(
336 const base::FilePath& local_path, 336 const base::FilePath& local_path,
337 const base::FilePath& virtual_path, 337 const base::FilePath& virtual_path,
338 const std::string& extension_id) { 338 const std::string& extension_id) {
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
340 340
341 EventRouter* event_router = 341 file_manager::EventRouter* event_router =
342 FileBrowserPrivateAPI::Get(profile_)->event_router(); 342 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router();
343 event_router->AddFileWatch( 343 event_router->AddFileWatch(
344 local_path, 344 local_path,
345 virtual_path, 345 virtual_path,
346 extension_id, 346 extension_id,
347 base::Bind(&AddFileWatchFunction::Respond, this)); 347 base::Bind(&AddFileWatchFunction::Respond, this));
348 } 348 }
349 349
350 RemoveFileWatchFunction::RemoveFileWatchFunction() { 350 RemoveFileWatchFunction::RemoveFileWatchFunction() {
351 } 351 }
352 352
353 RemoveFileWatchFunction::~RemoveFileWatchFunction() { 353 RemoveFileWatchFunction::~RemoveFileWatchFunction() {
354 } 354 }
355 355
356 void RemoveFileWatchFunction::PerformFileWatchOperation( 356 void RemoveFileWatchFunction::PerformFileWatchOperation(
357 const base::FilePath& local_path, 357 const base::FilePath& local_path,
358 const base::FilePath& unused, 358 const base::FilePath& unused,
359 const std::string& extension_id) { 359 const std::string& extension_id) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
361 361
362 EventRouter* event_router = 362 file_manager::EventRouter* event_router =
363 FileBrowserPrivateAPI::Get(profile_)->event_router(); 363 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router();
364 event_router->RemoveFileWatch(local_path, extension_id); 364 event_router->RemoveFileWatch(local_path, extension_id);
365 Respond(true); 365 Respond(true);
366 } 366 }
367 367
368 SetLastModifiedFunction::SetLastModifiedFunction() { 368 SetLastModifiedFunction::SetLastModifiedFunction() {
369 } 369 }
370 370
371 SetLastModifiedFunction::~SetLastModifiedFunction() { 371 SetLastModifiedFunction::~SetLastModifiedFunction() {
372 } 372 }
373 373
374 bool SetLastModifiedFunction::RunImpl() { 374 bool SetLastModifiedFunction::RunImpl() {
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
376 376
377 if (args_->GetSize() != 2) { 377 if (args_->GetSize() != 2) {
378 return false; 378 return false;
379 } 379 }
380 380
381 std::string file_url; 381 std::string file_url;
382 if (!args_->GetString(0, &file_url)) 382 if (!args_->GetString(0, &file_url))
383 return false; 383 return false;
384 384
385 std::string timestamp; 385 std::string timestamp;
386 if (!args_->GetString(1, &timestamp)) 386 if (!args_->GetString(1, &timestamp))
387 return false; 387 return false;
388 388
389 base::FilePath local_path = util::GetLocalPathFromURL( 389 base::FilePath local_path = file_manager::util::GetLocalPathFromURL(
390 render_view_host(), profile(), GURL(file_url)); 390 render_view_host(), profile(), GURL(file_url));
391 391
392 base::PostTaskAndReplyWithResult( 392 base::PostTaskAndReplyWithResult(
393 BrowserThread::GetBlockingPool(), 393 BrowserThread::GetBlockingPool(),
394 FROM_HERE, 394 FROM_HERE,
395 base::Bind(&SetLastModifiedOnBlockingPool, 395 base::Bind(&SetLastModifiedOnBlockingPool,
396 local_path, 396 local_path,
397 strtoul(timestamp.c_str(), NULL, 0)), 397 strtoul(timestamp.c_str(), NULL, 0)),
398 base::Bind(&SetLastModifiedFunction::SendResponse, 398 base::Bind(&SetLastModifiedFunction::SendResponse,
399 this)); 399 this));
400 return true; 400 return true;
401 } 401 }
402 402
403 GetSizeStatsFunction::GetSizeStatsFunction() { 403 GetSizeStatsFunction::GetSizeStatsFunction() {
404 } 404 }
405 405
406 GetSizeStatsFunction::~GetSizeStatsFunction() { 406 GetSizeStatsFunction::~GetSizeStatsFunction() {
407 } 407 }
408 408
409 bool GetSizeStatsFunction::RunImpl() { 409 bool GetSizeStatsFunction::RunImpl() {
410 if (args_->GetSize() != 1) { 410 if (args_->GetSize() != 1) {
411 return false; 411 return false;
412 } 412 }
413 413
414 std::string mount_url; 414 std::string mount_url;
415 if (!args_->GetString(0, &mount_url)) 415 if (!args_->GetString(0, &mount_url))
416 return false; 416 return false;
417 417
418 base::FilePath file_path = util::GetLocalPathFromURL( 418 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
419 render_view_host(), profile(), GURL(mount_url)); 419 render_view_host(), profile(), GURL(mount_url));
420 if (file_path.empty()) 420 if (file_path.empty())
421 return false; 421 return false;
422 422
423 if (file_path == drive::util::GetDriveMountPointPath()) { 423 if (file_path == drive::util::GetDriveMountPointPath()) {
424 drive::DriveIntegrationService* integration_service = 424 drive::DriveIntegrationService* integration_service =
425 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 425 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
426 // |integration_service| is NULL if Drive is disabled. 426 // |integration_service| is NULL if Drive is disabled.
427 if (!integration_service) { 427 if (!integration_service) {
428 // If stats couldn't be gotten for drive, result should be left 428 // If stats couldn't be gotten for drive, result should be left
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 error_ = "Invalid argument count"; 493 error_ = "Invalid argument count";
494 return false; 494 return false;
495 } 495 }
496 496
497 std::string volume_mount_url; 497 std::string volume_mount_url;
498 if (!args_->GetString(0, &volume_mount_url)) { 498 if (!args_->GetString(0, &volume_mount_url)) {
499 NOTREACHED(); 499 NOTREACHED();
500 return false; 500 return false;
501 } 501 }
502 502
503 base::FilePath file_path = util::GetLocalPathFromURL( 503 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
504 render_view_host(), profile(), GURL(volume_mount_url)); 504 render_view_host(), profile(), GURL(volume_mount_url));
505 if (file_path.empty()) { 505 if (file_path.empty()) {
506 error_ = "Invalid mount path."; 506 error_ = "Invalid mount path.";
507 return false; 507 return false;
508 } 508 }
509 509
510 results_.reset(); 510 results_.reset();
511 511
512 const DiskMountManager::Disk* volume = GetVolumeAsDisk(file_path.value()); 512 const DiskMountManager::Disk* volume = GetVolumeAsDisk(file_path.value());
513 if (volume) { 513 if (volume) {
(...skipping 15 matching lines...) Expand all
529 bool ValidatePathNameLengthFunction::RunImpl() { 529 bool ValidatePathNameLengthFunction::RunImpl() {
530 std::string parent_url; 530 std::string parent_url;
531 if (!args_->GetString(0, &parent_url)) 531 if (!args_->GetString(0, &parent_url))
532 return false; 532 return false;
533 533
534 std::string name; 534 std::string name;
535 if (!args_->GetString(1, &name)) 535 if (!args_->GetString(1, &name))
536 return false; 536 return false;
537 537
538 scoped_refptr<fileapi::FileSystemContext> file_system_context = 538 scoped_refptr<fileapi::FileSystemContext> file_system_context =
539 util::GetFileSystemContextForRenderViewHost( 539 file_manager::util::GetFileSystemContextForRenderViewHost(
540 profile(), render_view_host()); 540 profile(), render_view_host());
541 541
542 fileapi::FileSystemURL filesystem_url( 542 fileapi::FileSystemURL filesystem_url(
543 file_system_context->CrackURL(GURL(parent_url))); 543 file_system_context->CrackURL(GURL(parent_url)));
544 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) 544 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url))
545 return false; 545 return false;
546 546
547 // No explicit limit on the length of Drive file names. 547 // No explicit limit on the length of Drive file names.
548 if (filesystem_url.type() == fileapi::kFileSystemTypeDrive) { 548 if (filesystem_url.type() == fileapi::kFileSystemTypeDrive) {
549 SetResult(new base::FundamentalValue(true)); 549 SetResult(new base::FundamentalValue(true));
(...skipping 28 matching lines...) Expand all
578 if (args_->GetSize() != 1) { 578 if (args_->GetSize() != 1) {
579 return false; 579 return false;
580 } 580 }
581 581
582 std::string volume_file_url; 582 std::string volume_file_url;
583 if (!args_->GetString(0, &volume_file_url)) { 583 if (!args_->GetString(0, &volume_file_url)) {
584 NOTREACHED(); 584 NOTREACHED();
585 return false; 585 return false;
586 } 586 }
587 587
588 base::FilePath file_path = util::GetLocalPathFromURL( 588 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
589 render_view_host(), profile(), GURL(volume_file_url)); 589 render_view_host(), profile(), GURL(volume_file_url));
590 if (file_path.empty()) 590 if (file_path.empty())
591 return false; 591 return false;
592 592
593 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value()); 593 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value());
594 SendResponse(true); 594 SendResponse(true);
595 return true; 595 return true;
596 } 596 }
597 597
598 } // namespace file_manager 598 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698