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

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: 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
(...skipping 11 matching lines...) Expand all
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/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
32 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_paths_internal.h" 33 #include "chrome/common/chrome_paths_internal.h"
34 #include "chrome/common/pref_names.h"
33 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/notification_details.h"
34 #include "net/base/mime_util.h" 37 #include "net/base/mime_util.h"
35 #include "webkit/fileapi/file_system_file_util_proxy.h" 38 #include "webkit/fileapi/file_system_file_util_proxy.h"
36 #include "webkit/fileapi/file_system_types.h" 39 #include "webkit/fileapi/file_system_types.h"
37 #include "webkit/fileapi/file_system_util.h" 40 #include "webkit/fileapi/file_system_util.h"
38 41
39 using content::BrowserThread; 42 using content::BrowserThread;
40 43
41 namespace gdata { 44 namespace gdata {
42 namespace { 45 namespace {
43 46
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // GDataFileSystem class implementatsion. 475 // GDataFileSystem class implementatsion.
473 476
474 GDataFileSystem::GDataFileSystem(Profile* profile, 477 GDataFileSystem::GDataFileSystem(Profile* profile,
475 DocumentsServiceInterface* documents_service) 478 DocumentsServiceInterface* documents_service)
476 : profile_(profile), 479 : profile_(profile),
477 documents_service_(documents_service), 480 documents_service_(documents_service),
478 on_io_completed_(new base::WaitableEvent( 481 on_io_completed_(new base::WaitableEvent(
479 true /* manual reset */, false /* initially not signaled */)), 482 true /* manual reset */, false /* initially not signaled */)),
480 cache_initialization_started_(false), 483 cache_initialization_started_(false),
481 num_pending_tasks_(0), 484 num_pending_tasks_(0),
485 hide_hosted_docs_(false),
482 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( 486 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(
483 new base::WeakPtrFactory<GDataFileSystem>(this))), 487 new base::WeakPtrFactory<GDataFileSystem>(this))),
484 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()) { 488 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()) {
485 // Should be created from the file browser extension API on UI thread. 489 // Should be created from the file browser extension API on UI thread.
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
487 } 491 }
488 492
489 void GDataFileSystem::Initialize() { 493 void GDataFileSystem::Initialize() {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
491 FilePath cache_base_path; 495 FilePath cache_base_path;
492 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); 496 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path);
493 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); 497 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname);
494 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); 498 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir);
495 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType. 499 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType.
496 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir)); 500 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir));
497 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir)); 501 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir));
498 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir)); 502 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir));
499 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir)); 503 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir));
500 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir)); 504 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir));
501 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir)); 505 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir));
502 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDocumentsDir)); 506 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDocumentsDir));
503 507
504 documents_service_->Initialize(profile_); 508 documents_service_->Initialize(profile_);
505 509
506 root_.reset(new GDataRootDirectory(this)); 510 root_.reset(new GDataRootDirectory(this));
507 root_->set_file_name(kGDataRootDirectory); 511 root_->set_file_name(kGDataRootDirectory);
512
513 PrefService* pref_service = profile_->GetPrefs();
514 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
515
516 InitializePreferenceObserver();
508 } 517 }
509 518
510 GDataFileSystem::~GDataFileSystem() { 519 GDataFileSystem::~GDataFileSystem() {
511 // Should be deleted on IO thread by GDataSystemService. 520 // Should be deleted on IO thread by GDataSystemService.
512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
513 522
514 // io_weak_ptr_factory_ must be deleted on IO thread. 523 // io_weak_ptr_factory_ must be deleted on IO thread.
515 io_weak_ptr_factory_.reset(); 524 io_weak_ptr_factory_.reset();
516 // documents_service_ must be deleted on IO thread, as it also owns 525 // documents_service_ must be deleted on IO thread, as it also owns
517 // WeakPtrFactory bound to IO thread. 526 // WeakPtrFactory bound to IO thread.
(...skipping 2157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 resource_id = file->resource_id(); 2684 resource_id = file->resource_id();
2676 md5 = file->file_md5(); 2685 md5 = file->file_md5();
2677 parent_dir->AddFile(new_file.release()); 2686 parent_dir->AddFile(new_file.release());
2678 } 2687 }
2679 NotifyDirectoryChanged(virtual_dir_path); 2688 NotifyDirectoryChanged(virtual_dir_path);
2680 2689
2681 StoreToCache(resource_id, md5, file_content_path, cache_operation, 2690 StoreToCache(resource_id, md5, file_content_path, cache_operation,
2682 CacheOperationCallback()); 2691 CacheOperationCallback());
2683 } 2692 }
2684 2693
2694 void GDataFileSystem::Observe(int type,
2695 const content::NotificationSource& source,
2696 const content::NotificationDetails& details) {
2697 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
2698 PrefService* pref_service = profile_->GetPrefs();
2699 std::string* pref_name = content::Details<std::string>(details).ptr();
2700 if (*pref_name == prefs::kDisableGDataHostedFiles) {
2701 SetHideHostedDocuments(
2702 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles));
2703 } else if (*pref_name == prefs::kDisableGDataOverCellular) {
2704 // TODO(satorux): Disable pinning over mobil connection.
2705 } else if (*pref_name == prefs::kDisableGData) {
2706 // TODO(satorux): Disable gdata.
2707 }
satorux1 2012/04/04 21:23:16 Please remove TODOs. My part won't need code in GD
zel 2012/04/04 22:14:18 Done.
2708 } else {
2709 NOTREACHED();
2710 }
2711 }
2712
2713 bool GDataFileSystem::hide_hosted_documents() {
2714 base::AutoLock lock(lock_);
2715 return hide_hosted_docs_;
2716 }
2717
2718 void GDataFileSystem::SetHideHostedDocuments(bool hide) {
2719 FilePath root_path;
2720 {
2721 base::AutoLock lock(lock_);
2722 if (hide == hide_hosted_docs_)
2723 return;
2724
2725 hide_hosted_docs_ = hide;
2726 root_path = root_->GetFilePath();
2727 }
2728
2729 // Kick of directory refresh when this setting changes.
2730 NotifyDirectoryChanged(root_path);
2731 }
2685 2732
2686 //===================== GDataFileSystem: Cache entry points ==================== 2733 //===================== GDataFileSystem: Cache entry points ====================
2687 2734
2688 FilePath GDataFileSystem::GetCacheFilePath( 2735 FilePath GDataFileSystem::GetCacheFilePath(
2689 const std::string& resource_id, 2736 const std::string& resource_id,
2690 const std::string& md5, 2737 const std::string& md5,
2691 GDataRootDirectory::CacheSubDirectoryType sub_dir_type, 2738 GDataRootDirectory::CacheSubDirectoryType sub_dir_type,
2692 CachedFileOrigin file_origin) const { 2739 CachedFileOrigin file_origin) const {
2693 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META); 2740 DCHECK(sub_dir_type != GDataRootDirectory::CACHE_TYPE_META);
2694 2741
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
3762 const bool posted = BrowserThread::PostTaskAndReply( 3809 const bool posted = BrowserThread::PostTaskAndReply(
3763 BrowserThread::FILE, 3810 BrowserThread::FILE,
3764 from_here, 3811 from_here,
3765 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool, 3812 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool,
3766 base::Unretained(this), 3813 base::Unretained(this),
3767 request_task), 3814 request_task),
3768 reply_task); 3815 reply_task);
3769 DCHECK(posted); 3816 DCHECK(posted);
3770 } 3817 }
3771 3818
3819 void GDataFileSystem::InitializePreferenceObserver() {
3820 pref_observer_.reset(new PrefSetObserver(profile_->GetPrefs(), this));
achuithb 2012/04/04 19:14:11 pref_observer_ doesn't seem to do anything? What a
zel 2012/04/04 20:16:57 it does. it's a helper class for registering for m
achuithb 2012/04/04 20:46:19 Ah, got it. It takes care of the NotificationRegis
satorux1 2012/04/04 21:47:11 BTW, PrefChangeRegistar solves the same problem.
zel 2012/04/04 22:14:18 Done.
3821 pref_observer_->AddPref(prefs::kDisableGDataHostedFiles);
3822 pref_observer_->AddPref(prefs::kDisableGDataOverCellular);
3823 pref_observer_->AddPref(prefs::kDisableGData);
3824 }
3825
3772 } // namespace gdata 3826 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698