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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 9947002: Wired preference that hides hosted documents for the directory view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixes Created 8 years, 8 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/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/eintr_wrapper.h" 12 #include "base/eintr_wrapper.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/json/json_file_value_serializer.h" 14 #include "base/json/json_file_value_serializer.h"
15 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
16 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/message_loop_proxy.h" 18 #include "base/message_loop_proxy.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/platform_file.h" 20 #include "base/platform_file.h"
21 #include "base/threading/platform_thread.h" 21 #include "base/threading/platform_thread.h"
22 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" 25 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
26 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" 26 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
27 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h" 27 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h"
28 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 28 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
29 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" 29 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h"
30 #include "chrome/browser/prefs/pref_service.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/common/chrome_constants.h" 32 #include "chrome/common/chrome_constants.h"
33 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_paths_internal.h" 34 #include "chrome/common/chrome_paths_internal.h"
35 #include "chrome/common/pref_names.h"
33 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/notification_details.h"
34 #include "net/base/mime_util.h" 38 #include "net/base/mime_util.h"
35 #include "webkit/fileapi/file_system_file_util_proxy.h" 39 #include "webkit/fileapi/file_system_file_util_proxy.h"
36 #include "webkit/fileapi/file_system_types.h" 40 #include "webkit/fileapi/file_system_types.h"
37 #include "webkit/fileapi/file_system_util.h" 41 #include "webkit/fileapi/file_system_util.h"
38 42
39 using content::BrowserThread; 43 using content::BrowserThread;
40 44
41 namespace gdata { 45 namespace gdata {
42 namespace { 46 namespace {
43 47
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 // GDataFileSystem class implementatsion. 512 // GDataFileSystem class implementatsion.
509 513
510 GDataFileSystem::GDataFileSystem(Profile* profile, 514 GDataFileSystem::GDataFileSystem(Profile* profile,
511 DocumentsServiceInterface* documents_service) 515 DocumentsServiceInterface* documents_service)
512 : profile_(profile), 516 : profile_(profile),
513 documents_service_(documents_service), 517 documents_service_(documents_service),
514 on_io_completed_(new base::WaitableEvent( 518 on_io_completed_(new base::WaitableEvent(
515 true /* manual reset */, false /* initially not signaled */)), 519 true /* manual reset */, false /* initially not signaled */)),
516 cache_initialization_started_(false), 520 cache_initialization_started_(false),
517 num_pending_tasks_(0), 521 num_pending_tasks_(0),
522 hide_hosted_docs_(false),
518 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( 523 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(
519 new base::WeakPtrFactory<GDataFileSystem>(this))), 524 new base::WeakPtrFactory<GDataFileSystem>(this))),
520 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()) { 525 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()) {
521 // Should be created from the file browser extension API on UI thread. 526 // Should be created from the file browser extension API on UI thread.
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
523 } 528 }
524 529
525 void GDataFileSystem::Initialize() { 530 void GDataFileSystem::Initialize() {
526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
527 FilePath cache_base_path; 532 FilePath cache_base_path;
528 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); 533 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path);
529 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); 534 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname);
530 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); 535 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir);
531 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType. 536 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType.
532 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir)); 537 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir));
533 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir)); 538 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir));
534 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir)); 539 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir));
535 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir)); 540 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir));
536 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir)); 541 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir));
537 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir)); 542 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir));
538 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDocumentsDir)); 543 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDocumentsDir));
539 544
540 documents_service_->Initialize(profile_); 545 documents_service_->Initialize(profile_);
541 546
542 root_.reset(new GDataRootDirectory(this)); 547 root_.reset(new GDataRootDirectory(this));
543 root_->set_file_name(kGDataRootDirectory); 548 root_->set_file_name(kGDataRootDirectory);
549
550 PrefService* pref_service = profile_->GetPrefs();
551 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
552
553 InitializePreferenceObserver();
544 } 554 }
545 555
546 GDataFileSystem::~GDataFileSystem() { 556 GDataFileSystem::~GDataFileSystem() {
547 // Should be deleted on IO thread by GDataSystemService. 557 // Should be deleted on IO thread by GDataSystemService.
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
549 559
550 // io_weak_ptr_factory_ must be deleted on IO thread. 560 // io_weak_ptr_factory_ must be deleted on IO thread.
551 io_weak_ptr_factory_.reset(); 561 io_weak_ptr_factory_.reset();
552 // documents_service_ must be deleted on IO thread, as it also owns 562 // documents_service_ must be deleted on IO thread, as it also owns
553 // WeakPtrFactory bound to IO thread. 563 // WeakPtrFactory bound to IO thread.
(...skipping 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2837 resource_id = file->resource_id(); 2847 resource_id = file->resource_id();
2838 md5 = file->file_md5(); 2848 md5 = file->file_md5();
2839 parent_dir->AddFile(new_file.release()); 2849 parent_dir->AddFile(new_file.release());
2840 } 2850 }
2841 NotifyDirectoryChanged(virtual_dir_path); 2851 NotifyDirectoryChanged(virtual_dir_path);
2842 2852
2843 StoreToCache(resource_id, md5, file_content_path, cache_operation, 2853 StoreToCache(resource_id, md5, file_content_path, cache_operation,
2844 CacheOperationCallback()); 2854 CacheOperationCallback());
2845 } 2855 }
2846 2856
2857 void GDataFileSystem::Observe(int type,
2858 const content::NotificationSource& source,
2859 const content::NotificationDetails& details) {
2860 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
2861 PrefService* pref_service = profile_->GetPrefs();
2862 std::string* pref_name = content::Details<std::string>(details).ptr();
2863 if (*pref_name == prefs::kDisableGDataHostedFiles) {
2864 SetHideHostedDocuments(
2865 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles));
2866 }
2867 } else {
2868 NOTREACHED();
2869 }
2870 }
2871
2872 bool GDataFileSystem::hide_hosted_documents() {
2873 base::AutoLock lock(lock_);
2874 return hide_hosted_docs_;
2875 }
2876
2877 void GDataFileSystem::SetHideHostedDocuments(bool hide) {
2878 FilePath root_path;
2879 {
2880 base::AutoLock lock(lock_);
2881 if (hide == hide_hosted_docs_)
2882 return;
2883
2884 hide_hosted_docs_ = hide;
2885 root_path = root_->GetFilePath();
2886 }
2887
2888 // Kick of directory refresh when this setting changes.
2889 NotifyDirectoryChanged(root_path);
2890 }
2847 2891
2848 //===================== GDataFileSystem: Cache entry points ==================== 2892 //===================== GDataFileSystem: Cache entry points ====================
2849 2893
2850 FilePath GDataFileSystem::GetCacheFilePath( 2894 FilePath GDataFileSystem::GetCacheFilePath(
2851 const std::string& resource_id, 2895 const std::string& resource_id,
2852 const std::string& md5, 2896 const std::string& md5,
2853 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, 2897 GDataRootDirectory::CacheSubDirectoryType sub_dir_type,
2854 CachedFileOrigin file_origin) const { 2898 CachedFileOrigin file_origin) const {
2855 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); 2899 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META);
2856 2900
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 const bool posted = BrowserThread::PostTaskAndReply( 3968 const bool posted = BrowserThread::PostTaskAndReply(
3925 BrowserThread::FILE, 3969 BrowserThread::FILE,
3926 from_here, 3970 from_here,
3927 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool, 3971 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool,
3928 base::Unretained(this), 3972 base::Unretained(this),
3929 request_task), 3973 request_task),
3930 reply_task); 3974 reply_task);
3931 DCHECK(posted); 3975 DCHECK(posted);
3932 } 3976 }
3933 3977
3978 void GDataFileSystem::InitializePreferenceObserver() {
3979 pref_registrar_.Init(profile_->GetPrefs());
3980 pref_registrar_.Add(prefs::kDisableGDataHostedFiles, this);
3981 }
3982
3934 } // namespace gdata 3983 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698