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

Side by Side Diff: chrome/browser/chromeos/file_manager/volume_manager.cc

Issue 23477070: Move OnFileSystemMounted/BeingUnmounted to VolumeManager. (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/file_manager/volume_manager.h" 5 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
15 #include "chrome/browser/chromeos/drive/file_errors.h" 16 #include "chrome/browser/chromeos/drive/file_errors.h"
16 #include "chrome/browser/chromeos/drive/file_system_interface.h" 17 #include "chrome/browser/chromeos/drive/file_system_interface.h"
17 #include "chrome/browser/chromeos/drive/file_system_util.h" 18 #include "chrome/browser/chromeos/drive/file_system_util.h"
18 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" 19 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h"
19 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h" 20 #include "chrome/browser/chromeos/file_manager/volume_manager_factory.h"
20 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" 21 #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chromeos/dbus/cros_disks_client.h" 24 #include "chromeos/dbus/cros_disks_client.h"
24 #include "chromeos/disks/disk_mount_manager.h" 25 #include "chromeos/disks/disk_mount_manager.h"
(...skipping 14 matching lines...) Expand all
39 return VOLUME_TYPE_REMOVABLE_DISK_PARTITION; 40 return VOLUME_TYPE_REMOVABLE_DISK_PARTITION;
40 case chromeos::MOUNT_TYPE_ARCHIVE: 41 case chromeos::MOUNT_TYPE_ARCHIVE:
41 return VOLUME_TYPE_MOUNTED_ARCHIVE_FILE; 42 return VOLUME_TYPE_MOUNTED_ARCHIVE_FILE;
42 default: 43 default:
43 NOTREACHED(); 44 NOTREACHED();
44 } 45 }
45 46
46 return VOLUME_TYPE_DOWNLOADS_DIRECTORY; 47 return VOLUME_TYPE_DOWNLOADS_DIRECTORY;
47 } 48 }
48 49
50 // Returns the VolumeInfo for Drive file system.
51 VolumeInfo CreateDriveVolumeInfo() {
52 const base::FilePath& drive_path = drive::util::GetDriveMountPointPath();
53
54 VolumeInfo volume_info;
55 volume_info.type = VOLUME_TYPE_GOOGLE_DRIVE;
56 volume_info.source_path = drive_path;
57 volume_info.mount_path = drive_path;
58 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
59 volume_info.is_parent = false;
60 return volume_info;
61 }
62
49 VolumeInfo CreateDownloadsVolumeInfo( 63 VolumeInfo CreateDownloadsVolumeInfo(
50 const base::FilePath& downloads_path) { 64 const base::FilePath& downloads_path) {
51 VolumeInfo volume_info; 65 VolumeInfo volume_info;
52 volume_info.type = VOLUME_TYPE_DOWNLOADS_DIRECTORY; 66 volume_info.type = VOLUME_TYPE_DOWNLOADS_DIRECTORY;
53 // Keep source_path empty. 67 // Keep source_path empty.
54 volume_info.mount_path = downloads_path; 68 volume_info.mount_path = downloads_path;
55 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE; 69 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
56 volume_info.is_parent = false; 70 volume_info.is_parent = false;
57 return volume_info; 71 return volume_info;
58 } 72 }
(...skipping 19 matching lines...) Expand all
78 } 92 }
79 93
80 } // namespace 94 } // namespace
81 95
82 VolumeInfo::VolumeInfo() { 96 VolumeInfo::VolumeInfo() {
83 } 97 }
84 98
85 VolumeInfo::~VolumeInfo() { 99 VolumeInfo::~VolumeInfo() {
86 } 100 }
87 101
88 VolumeInfo CreateDriveVolumeInfo() {
89 const base::FilePath& drive_path = drive::util::GetDriveMountPointPath();
90
91 VolumeInfo volume_info;
92 volume_info.type = VOLUME_TYPE_GOOGLE_DRIVE;
93 volume_info.source_path = drive_path;
94 volume_info.mount_path = drive_path;
95 volume_info.mount_condition = chromeos::disks::MOUNT_CONDITION_NONE;
96 volume_info.is_parent = false;
97 return volume_info;
98 }
99
100 VolumeManager::VolumeManager( 102 VolumeManager::VolumeManager(
101 Profile* profile, 103 Profile* profile,
104 drive::DriveIntegrationService* drive_integration_service,
102 chromeos::PowerManagerClient* power_manager_client, 105 chromeos::PowerManagerClient* power_manager_client,
103 chromeos::disks::DiskMountManager* disk_mount_manager) 106 chromeos::disks::DiskMountManager* disk_mount_manager)
104 : profile_(profile), 107 : profile_(profile),
108 drive_integration_service_(drive_integration_service),
105 disk_mount_manager_(disk_mount_manager), 109 disk_mount_manager_(disk_mount_manager),
106 mounted_disk_monitor_( 110 mounted_disk_monitor_(
107 new MountedDiskMonitor(power_manager_client, disk_mount_manager)) { 111 new MountedDiskMonitor(power_manager_client, disk_mount_manager)) {
108 DCHECK(disk_mount_manager); 112 DCHECK(disk_mount_manager);
109 } 113 }
110 114
111 VolumeManager::~VolumeManager() { 115 VolumeManager::~VolumeManager() {
112 } 116 }
113 117
114 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { 118 VolumeManager* VolumeManager::Get(content::BrowserContext* context) {
115 return VolumeManagerFactory::Get(context); 119 return VolumeManagerFactory::Get(context);
116 } 120 }
117 121
118 void VolumeManager::Initialize() { 122 void VolumeManager::Initialize() {
123 if (drive_integration_service_)
124 drive_integration_service_->AddObserver(this);
125
119 // Subscribe to DiskMountManager. 126 // Subscribe to DiskMountManager.
120 disk_mount_manager_->AddObserver(this); 127 disk_mount_manager_->AddObserver(this);
121 disk_mount_manager_->RequestMountInfoRefresh(); 128 disk_mount_manager_->RequestMountInfoRefresh();
122 129
123 // Subscribe to Profile Preference change. 130 // Subscribe to Profile Preference change.
124 pref_change_registrar_.Init(profile_->GetPrefs()); 131 pref_change_registrar_.Init(profile_->GetPrefs());
125 pref_change_registrar_.Add( 132 pref_change_registrar_.Add(
126 prefs::kExternalStorageDisabled, 133 prefs::kExternalStorageDisabled,
127 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, 134 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged,
128 base::Unretained(this))); 135 base::Unretained(this)));
129 } 136 }
130 137
131 void VolumeManager::Shutdown() { 138 void VolumeManager::Shutdown() {
132 pref_change_registrar_.RemoveAll(); 139 pref_change_registrar_.RemoveAll();
133 disk_mount_manager_->RemoveObserver(this); 140 disk_mount_manager_->RemoveObserver(this);
141
142 if (drive_integration_service_)
143 drive_integration_service_->RemoveObserver(this);
134 } 144 }
135 145
136 void VolumeManager::AddObserver(VolumeManagerObserver* observer) { 146 void VolumeManager::AddObserver(VolumeManagerObserver* observer) {
137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 147 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
138 DCHECK(observer); 148 DCHECK(observer);
139 observers_.AddObserver(observer); 149 observers_.AddObserver(observer);
140 } 150 }
141 151
142 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { 152 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) {
143 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 153 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 24 matching lines...) Expand all
168 if (it->second.mount_type == chromeos::MOUNT_TYPE_DEVICE || 178 if (it->second.mount_type == chromeos::MOUNT_TYPE_DEVICE ||
169 it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) 179 it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE)
170 result.push_back(CreateVolumeInfoFromMountPointInfo( 180 result.push_back(CreateVolumeInfoFromMountPointInfo(
171 it->second, 181 it->second,
172 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path))); 182 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)));
173 } 183 }
174 184
175 return result; 185 return result;
176 } 186 }
177 187
188 void VolumeManager::OnFileSystemMounted() {
189 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
190
191 // Raise mount event.
192 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
193 // or network is unreachable. These two errors will be handled later.
194 VolumeInfo volume_info = CreateDriveVolumeInfo();
195 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_,
196 OnVolumeMounted(chromeos::MOUNT_ERROR_NONE,
197 volume_info,
198 false)); // Not remounting.
199 }
200
201 void VolumeManager::OnFileSystemBeingUnmounted() {
202 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
203
204 VolumeInfo volume_info = CreateDriveVolumeInfo();
205 FOR_EACH_OBSERVER(
206 VolumeManagerObserver, observers_,
207 OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, volume_info));
208 }
209
178 void VolumeManager::OnDiskEvent( 210 void VolumeManager::OnDiskEvent(
179 chromeos::disks::DiskMountManager::DiskEvent event, 211 chromeos::disks::DiskMountManager::DiskEvent event,
180 const chromeos::disks::DiskMountManager::Disk* disk) { 212 const chromeos::disks::DiskMountManager::Disk* disk) {
181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
182 214
183 // Disregard hidden devices. 215 // Disregard hidden devices.
184 if (disk->is_hidden()) 216 if (disk->is_hidden())
185 return; 217 return;
186 218
187 switch (event) { 219 switch (event) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 LOG(INFO) << "Unmounting " << mount_path << " because of preference."; 384 LOG(INFO) << "Unmounting " << mount_path << " because of preference.";
353 disk_mount_manager_->UnmountPath( 385 disk_mount_manager_->UnmountPath(
354 mount_path, 386 mount_path,
355 chromeos::UNMOUNT_OPTIONS_NONE, 387 chromeos::UNMOUNT_OPTIONS_NONE,
356 chromeos::disks::DiskMountManager::UnmountPathCallback()); 388 chromeos::disks::DiskMountManager::UnmountPathCallback());
357 } 389 }
358 } 390 }
359 } 391 }
360 392
361 } // namespace file_manager 393 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | chrome/browser/chromeos/file_manager/volume_manager_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698