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

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: Rebased Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_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 26 matching lines...) Expand all
37 #include "webkit/common/fileapi/file_system_types.h" 37 #include "webkit/common/fileapi/file_system_types.h"
38 #include "webkit/common/fileapi/file_system_util.h" 38 #include "webkit/common/fileapi/file_system_util.h"
39 39
40 using chromeos::disks::DiskMountManager; 40 using chromeos::disks::DiskMountManager;
41 using content::BrowserContext; 41 using content::BrowserContext;
42 using content::BrowserThread; 42 using content::BrowserThread;
43 using content::ChildProcessSecurityPolicy; 43 using content::ChildProcessSecurityPolicy;
44 using content::WebContents; 44 using content::WebContents;
45 using fileapi::FileSystemURL; 45 using fileapi::FileSystemURL;
46 46
47 namespace file_manager { 47 namespace extensions {
48 namespace { 48 namespace {
49 49
50 // Error messages. 50 // Error messages.
51 const char kFileError[] = "File error %d"; 51 const char kFileError[] = "File error %d";
52 52
53 const DiskMountManager::Disk* GetVolumeAsDisk(const std::string& mount_path) { 53 const DiskMountManager::Disk* GetVolumeAsDisk(const std::string& mount_path) {
54 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 54 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
55 55
56 DiskMountManager::MountPointMap::const_iterator mount_point_it = 56 DiskMountManager::MountPointMap::const_iterator mount_point_it =
57 disk_mount_manager->mount_points().find(mount_path); 57 disk_mount_manager->mount_points().find(mount_path);
58 if (mount_point_it == disk_mount_manager->mount_points().end()) 58 if (mount_point_it == disk_mount_manager->mount_points().end())
59 return NULL; 59 return NULL;
60 60
61 const DiskMountManager::Disk* disk = disk_mount_manager->FindDiskBySourcePath( 61 const DiskMountManager::Disk* disk = disk_mount_manager->FindDiskBySourcePath(
62 mount_point_it->second.source_path); 62 mount_point_it->second.source_path);
63 63
64 return (disk && disk->is_hidden()) ? NULL : disk; 64 return (disk && disk->is_hidden()) ? NULL : disk;
65 } 65 }
66 66
67 base::DictionaryValue* CreateValueFromDisk( 67 base::DictionaryValue* CreateValueFromDisk(
68 Profile* profile, 68 Profile* profile,
69 const std::string& extension_id, 69 const std::string& extension_id,
70 const DiskMountManager::Disk* volume) { 70 const DiskMountManager::Disk* volume) {
71 base::DictionaryValue* volume_info = new base::DictionaryValue(); 71 base::DictionaryValue* volume_info = new base::DictionaryValue();
72 72
73 std::string mount_path; 73 std::string mount_path;
74 if (!volume->mount_path().empty()) { 74 if (!volume->mount_path().empty()) {
75 base::FilePath relative_mount_path; 75 base::FilePath relative_mount_path;
76 util::ConvertAbsoluteFilePathToRelativeFileSystemPath( 76 file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
77 profile, extension_id, base::FilePath(volume->mount_path()), 77 profile, extension_id, base::FilePath(volume->mount_path()),
78 &relative_mount_path); 78 &relative_mount_path);
79 mount_path = relative_mount_path.value(); 79 mount_path = relative_mount_path.value();
80 } 80 }
81 81
82 volume_info->SetString("devicePath", volume->device_path()); 82 volume_info->SetString("devicePath", volume->device_path());
83 volume_info->SetString("mountPath", mount_path); 83 volume_info->SetString("mountPath", mount_path);
84 volume_info->SetString("systemPath", volume->system_path()); 84 volume_info->SetString("systemPath", volume->system_path());
85 volume_info->SetString("filePath", volume->file_path()); 85 volume_info->SetString("filePath", volume->file_path());
86 volume_info->SetString("deviceLabel", volume->device_label()); 86 volume_info->SetString("deviceLabel", volume->device_label());
(...skipping 24 matching lines...) Expand all
111 void SetDriveMountPointPermissions( 111 void SetDriveMountPointPermissions(
112 Profile* profile, 112 Profile* profile,
113 const std::string& extension_id, 113 const std::string& extension_id,
114 content::RenderViewHost* render_view_host) { 114 content::RenderViewHost* render_view_host) {
115 if (!render_view_host || 115 if (!render_view_host ||
116 !render_view_host->GetSiteInstance() || !render_view_host->GetProcess()) { 116 !render_view_host->GetSiteInstance() || !render_view_host->GetProcess()) {
117 return; 117 return;
118 } 118 }
119 119
120 fileapi::ExternalFileSystemBackend* backend = 120 fileapi::ExternalFileSystemBackend* backend =
121 util::GetFileSystemContextForRenderViewHost( 121 file_manager::util::GetFileSystemContextForRenderViewHost(
122 profile, render_view_host)->external_backend(); 122 profile, render_view_host)->external_backend();
123 if (!backend) 123 if (!backend)
124 return; 124 return;
125 125
126 const base::FilePath mount_point = drive::util::GetDriveMountPointPath(); 126 const base::FilePath mount_point = drive::util::GetDriveMountPointPath();
127 // Grant R/W permissions to drive 'folder'. File API layer still 127 // Grant R/W permissions to drive 'folder'. File API layer still
128 // expects this to be satisfied. 128 // expects this to be satisfied.
129 ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile( 129 ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile(
130 render_view_host->GetProcess()->GetID(), mount_point); 130 render_view_host->GetProcess()->GetID(), mount_point);
131 131
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 273
274 bool RequestFileSystemFunction::RunImpl() { 274 bool RequestFileSystemFunction::RunImpl() {
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
276 276
277 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess()) 277 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess())
278 return false; 278 return false;
279 279
280 set_log_on_completion(true); 280 set_log_on_completion(true);
281 281
282 scoped_refptr<fileapi::FileSystemContext> file_system_context = 282 scoped_refptr<fileapi::FileSystemContext> file_system_context =
283 util::GetFileSystemContextForRenderViewHost( 283 file_manager::util::GetFileSystemContextForRenderViewHost(
284 profile(), render_view_host()); 284 profile(), render_view_host());
285 285
286 const GURL origin_url = source_url_.GetOrigin(); 286 const GURL origin_url = source_url_.GetOrigin();
287 file_system_context->OpenFileSystem( 287 file_system_context->OpenFileSystem(
288 origin_url, 288 origin_url,
289 fileapi::kFileSystemTypeExternal, 289 fileapi::kFileSystemTypeExternal,
290 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, 290 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
291 base::Bind(&RequestFileSystemFunction::DidOpenFileSystem, 291 base::Bind(&RequestFileSystemFunction::DidOpenFileSystem,
292 this, 292 this,
293 file_system_context)); 293 file_system_context));
(...skipping 18 matching lines...) Expand all
312 312
313 if (!render_view_host() || !render_view_host()->GetProcess()) 313 if (!render_view_host() || !render_view_host()->GetProcess())
314 return false; 314 return false;
315 315
316 // First param is url of a file to watch. 316 // First param is url of a file to watch.
317 std::string url; 317 std::string url;
318 if (!args_->GetString(0, &url) || url.empty()) 318 if (!args_->GetString(0, &url) || url.empty())
319 return false; 319 return false;
320 320
321 scoped_refptr<fileapi::FileSystemContext> file_system_context = 321 scoped_refptr<fileapi::FileSystemContext> file_system_context =
322 util::GetFileSystemContextForRenderViewHost( 322 file_manager::util::GetFileSystemContextForRenderViewHost(
323 profile(), render_view_host()); 323 profile(), render_view_host());
324 324
325 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); 325 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url));
326 base::FilePath local_path = file_watch_url.path(); 326 base::FilePath local_path = file_watch_url.path();
327 base::FilePath virtual_path = file_watch_url.virtual_path(); 327 base::FilePath virtual_path = file_watch_url.virtual_path();
328 if (local_path.empty()) { 328 if (local_path.empty()) {
329 Respond(false); 329 Respond(false);
330 return true; 330 return true;
331 } 331 }
332 PerformFileWatchOperation(local_path, virtual_path, extension_id()); 332 PerformFileWatchOperation(local_path, virtual_path, extension_id());
333 333
334 return true; 334 return true;
335 } 335 }
336 336
337 AddFileWatchFunction::AddFileWatchFunction() { 337 AddFileWatchFunction::AddFileWatchFunction() {
338 } 338 }
339 339
340 AddFileWatchFunction::~AddFileWatchFunction() { 340 AddFileWatchFunction::~AddFileWatchFunction() {
341 } 341 }
342 342
343 void AddFileWatchFunction::PerformFileWatchOperation( 343 void AddFileWatchFunction::PerformFileWatchOperation(
344 const base::FilePath& local_path, 344 const base::FilePath& local_path,
345 const base::FilePath& virtual_path, 345 const base::FilePath& virtual_path,
346 const std::string& extension_id) { 346 const std::string& extension_id) {
347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
348 348
349 EventRouter* event_router = 349 file_manager::EventRouter* event_router =
350 FileBrowserPrivateAPI::Get(profile_)->event_router(); 350 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router();
351 event_router->AddFileWatch( 351 event_router->AddFileWatch(
352 local_path, 352 local_path,
353 virtual_path, 353 virtual_path,
354 extension_id, 354 extension_id,
355 base::Bind(&AddFileWatchFunction::Respond, this)); 355 base::Bind(&AddFileWatchFunction::Respond, this));
356 } 356 }
357 357
358 RemoveFileWatchFunction::RemoveFileWatchFunction() { 358 RemoveFileWatchFunction::RemoveFileWatchFunction() {
359 } 359 }
360 360
361 RemoveFileWatchFunction::~RemoveFileWatchFunction() { 361 RemoveFileWatchFunction::~RemoveFileWatchFunction() {
362 } 362 }
363 363
364 void RemoveFileWatchFunction::PerformFileWatchOperation( 364 void RemoveFileWatchFunction::PerformFileWatchOperation(
365 const base::FilePath& local_path, 365 const base::FilePath& local_path,
366 const base::FilePath& unused, 366 const base::FilePath& unused,
367 const std::string& extension_id) { 367 const std::string& extension_id) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
369 369
370 EventRouter* event_router = 370 file_manager::EventRouter* event_router =
371 FileBrowserPrivateAPI::Get(profile_)->event_router(); 371 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router();
372 event_router->RemoveFileWatch(local_path, extension_id); 372 event_router->RemoveFileWatch(local_path, extension_id);
373 Respond(true); 373 Respond(true);
374 } 374 }
375 375
376 SetLastModifiedFunction::SetLastModifiedFunction() { 376 SetLastModifiedFunction::SetLastModifiedFunction() {
377 } 377 }
378 378
379 SetLastModifiedFunction::~SetLastModifiedFunction() { 379 SetLastModifiedFunction::~SetLastModifiedFunction() {
380 } 380 }
381 381
382 bool SetLastModifiedFunction::RunImpl() { 382 bool SetLastModifiedFunction::RunImpl() {
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
384 384
385 if (args_->GetSize() != 2) { 385 if (args_->GetSize() != 2) {
386 return false; 386 return false;
387 } 387 }
388 388
389 std::string file_url; 389 std::string file_url;
390 if (!args_->GetString(0, &file_url)) 390 if (!args_->GetString(0, &file_url))
391 return false; 391 return false;
392 392
393 std::string timestamp; 393 std::string timestamp;
394 if (!args_->GetString(1, &timestamp)) 394 if (!args_->GetString(1, &timestamp))
395 return false; 395 return false;
396 396
397 base::FilePath local_path = util::GetLocalPathFromURL( 397 base::FilePath local_path = file_manager::util::GetLocalPathFromURL(
398 render_view_host(), profile(), GURL(file_url)); 398 render_view_host(), profile(), GURL(file_url));
399 399
400 base::PostTaskAndReplyWithResult( 400 base::PostTaskAndReplyWithResult(
401 BrowserThread::GetBlockingPool(), 401 BrowserThread::GetBlockingPool(),
402 FROM_HERE, 402 FROM_HERE,
403 base::Bind(&SetLastModifiedOnBlockingPool, 403 base::Bind(&SetLastModifiedOnBlockingPool,
404 local_path, 404 local_path,
405 strtoul(timestamp.c_str(), NULL, 0)), 405 strtoul(timestamp.c_str(), NULL, 0)),
406 base::Bind(&SetLastModifiedFunction::SendResponse, 406 base::Bind(&SetLastModifiedFunction::SendResponse,
407 this)); 407 this));
408 return true; 408 return true;
409 } 409 }
410 410
411 GetSizeStatsFunction::GetSizeStatsFunction() { 411 GetSizeStatsFunction::GetSizeStatsFunction() {
412 } 412 }
413 413
414 GetSizeStatsFunction::~GetSizeStatsFunction() { 414 GetSizeStatsFunction::~GetSizeStatsFunction() {
415 } 415 }
416 416
417 bool GetSizeStatsFunction::RunImpl() { 417 bool GetSizeStatsFunction::RunImpl() {
418 if (args_->GetSize() != 1) { 418 if (args_->GetSize() != 1) {
419 return false; 419 return false;
420 } 420 }
421 421
422 std::string mount_url; 422 std::string mount_url;
423 if (!args_->GetString(0, &mount_url)) 423 if (!args_->GetString(0, &mount_url))
424 return false; 424 return false;
425 425
426 base::FilePath file_path = util::GetLocalPathFromURL( 426 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
427 render_view_host(), profile(), GURL(mount_url)); 427 render_view_host(), profile(), GURL(mount_url));
428 if (file_path.empty()) 428 if (file_path.empty())
429 return false; 429 return false;
430 430
431 if (file_path == drive::util::GetDriveMountPointPath()) { 431 if (file_path == drive::util::GetDriveMountPointPath()) {
432 drive::DriveIntegrationService* integration_service = 432 drive::DriveIntegrationService* integration_service =
433 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); 433 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
434 // |integration_service| is NULL if Drive is disabled. 434 // |integration_service| is NULL if Drive is disabled.
435 if (!integration_service) { 435 if (!integration_service) {
436 // If stats couldn't be gotten for drive, result should be left 436 // If stats couldn't be gotten for drive, result should be left
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 error_ = "Invalid argument count"; 501 error_ = "Invalid argument count";
502 return false; 502 return false;
503 } 503 }
504 504
505 std::string volume_mount_url; 505 std::string volume_mount_url;
506 if (!args_->GetString(0, &volume_mount_url)) { 506 if (!args_->GetString(0, &volume_mount_url)) {
507 NOTREACHED(); 507 NOTREACHED();
508 return false; 508 return false;
509 } 509 }
510 510
511 base::FilePath file_path = util::GetLocalPathFromURL( 511 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
512 render_view_host(), profile(), GURL(volume_mount_url)); 512 render_view_host(), profile(), GURL(volume_mount_url));
513 if (file_path.empty()) { 513 if (file_path.empty()) {
514 error_ = "Invalid mount path."; 514 error_ = "Invalid mount path.";
515 return false; 515 return false;
516 } 516 }
517 517
518 results_.reset(); 518 results_.reset();
519 519
520 base::FilePath home_path; 520 base::FilePath home_path;
521 // TODO(hidehiko): Return the volume info for Drive File System. 521 // TODO(hidehiko): Return the volume info for Drive File System.
(...skipping 20 matching lines...) Expand all
542 bool ValidatePathNameLengthFunction::RunImpl() { 542 bool ValidatePathNameLengthFunction::RunImpl() {
543 std::string parent_url; 543 std::string parent_url;
544 if (!args_->GetString(0, &parent_url)) 544 if (!args_->GetString(0, &parent_url))
545 return false; 545 return false;
546 546
547 std::string name; 547 std::string name;
548 if (!args_->GetString(1, &name)) 548 if (!args_->GetString(1, &name))
549 return false; 549 return false;
550 550
551 scoped_refptr<fileapi::FileSystemContext> file_system_context = 551 scoped_refptr<fileapi::FileSystemContext> file_system_context =
552 util::GetFileSystemContextForRenderViewHost( 552 file_manager::util::GetFileSystemContextForRenderViewHost(
553 profile(), render_view_host()); 553 profile(), render_view_host());
554 554
555 fileapi::FileSystemURL filesystem_url( 555 fileapi::FileSystemURL filesystem_url(
556 file_system_context->CrackURL(GURL(parent_url))); 556 file_system_context->CrackURL(GURL(parent_url)));
557 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) 557 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url))
558 return false; 558 return false;
559 559
560 // No explicit limit on the length of Drive file names. 560 // No explicit limit on the length of Drive file names.
561 if (filesystem_url.type() == fileapi::kFileSystemTypeDrive) { 561 if (filesystem_url.type() == fileapi::kFileSystemTypeDrive) {
562 SetResult(new base::FundamentalValue(true)); 562 SetResult(new base::FundamentalValue(true));
(...skipping 28 matching lines...) Expand all
591 if (args_->GetSize() != 1) { 591 if (args_->GetSize() != 1) {
592 return false; 592 return false;
593 } 593 }
594 594
595 std::string volume_file_url; 595 std::string volume_file_url;
596 if (!args_->GetString(0, &volume_file_url)) { 596 if (!args_->GetString(0, &volume_file_url)) {
597 NOTREACHED(); 597 NOTREACHED();
598 return false; 598 return false;
599 } 599 }
600 600
601 base::FilePath file_path = util::GetLocalPathFromURL( 601 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
602 render_view_host(), profile(), GURL(volume_file_url)); 602 render_view_host(), profile(), GURL(volume_file_url));
603 if (file_path.empty()) 603 if (file_path.empty())
604 return false; 604 return false;
605 605
606 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value()); 606 DiskMountManager::GetInstance()->FormatMountedDevice(file_path.value());
607 SendResponse(true); 607 SendResponse(true);
608 return true; 608 return true;
609 } 609 }
610 610
611 } // namespace file_manager 611 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698