| OLD | NEW |
| 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 // RemovableDeviceNotificationsLinux implementation. | 5 // RemovableDeviceNotificationsLinux implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" | 7 #include "chrome/browser/system_monitor/removable_device_notifications_linux.h" |
| 8 | 8 |
| 9 #include <libudev.h> | 9 #include <libudev.h> |
| 10 #include <mntent.h> | 10 #include <mntent.h> |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 RemovableDeviceNotificationsLinux::MountPointInfo::MountPointInfo() { | 234 RemovableDeviceNotificationsLinux::MountPointInfo::MountPointInfo() { |
| 235 } | 235 } |
| 236 | 236 |
| 237 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux( | 237 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux( |
| 238 const FilePath& path) | 238 const FilePath& path) |
| 239 : initialized_(false), | 239 : initialized_(false), |
| 240 mtab_path_(path), | 240 mtab_path_(path), |
| 241 get_device_info_func_(&GetDeviceInfo) { | 241 get_device_info_func_(&GetDeviceInfo) { |
| 242 DCHECK(!g_removable_device_notifications_linux); | 242 DCHECK(!g_removable_device_notifications_linux); |
| 243 g_removable_device_notifications_linux = this; | 243 g_removable_device_notifications_linux = this; |
| 244 |
| 245 if (SystemMonitor::Get()) |
| 246 SystemMonitor::Get()->set_storage_free_space_delegate(this); |
| 244 } | 247 } |
| 245 | 248 |
| 246 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux( | 249 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux( |
| 247 const FilePath& path, | 250 const FilePath& path, |
| 248 GetDeviceInfoFunc get_device_info_func) | 251 GetDeviceInfoFunc get_device_info_func) |
| 249 : initialized_(false), | 252 : initialized_(false), |
| 250 mtab_path_(path), | 253 mtab_path_(path), |
| 251 get_device_info_func_(get_device_info_func) { | 254 get_device_info_func_(get_device_info_func) { |
| 252 DCHECK(!g_removable_device_notifications_linux); | 255 DCHECK(!g_removable_device_notifications_linux); |
| 253 g_removable_device_notifications_linux = this; | 256 g_removable_device_notifications_linux = this; |
| 254 } | 257 } |
| 255 | 258 |
| 256 RemovableDeviceNotificationsLinux::~RemovableDeviceNotificationsLinux() { | 259 RemovableDeviceNotificationsLinux::~RemovableDeviceNotificationsLinux() { |
| 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 258 DCHECK_EQ(this, g_removable_device_notifications_linux); | 261 DCHECK_EQ(this, g_removable_device_notifications_linux); |
| 259 g_removable_device_notifications_linux = NULL; | 262 g_removable_device_notifications_linux = NULL; |
| 263 if (SystemMonitor::Get() && |
| 264 SystemMonitor::Get()->storage_free_space_delegate()) |
| 265 SystemMonitor::Get()->set_storage_free_space_delegate(NULL); |
| 260 } | 266 } |
| 261 | 267 |
| 262 // static | 268 // static |
| 263 RemovableDeviceNotificationsLinux* | 269 RemovableDeviceNotificationsLinux* |
| 264 RemovableDeviceNotificationsLinux::GetInstance() { | 270 RemovableDeviceNotificationsLinux::GetInstance() { |
| 265 DCHECK(g_removable_device_notifications_linux != NULL); | 271 DCHECK(g_removable_device_notifications_linux != NULL); |
| 266 return g_removable_device_notifications_linux; | 272 return g_removable_device_notifications_linux; |
| 267 } | 273 } |
| 268 | 274 |
| 269 void RemovableDeviceNotificationsLinux::Init() { | 275 void RemovableDeviceNotificationsLinux::Init() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 } | 355 } |
| 350 | 356 |
| 351 UpdateMtab(); | 357 UpdateMtab(); |
| 352 } | 358 } |
| 353 | 359 |
| 354 void RemovableDeviceNotificationsLinux::InitOnFileThread() { | 360 void RemovableDeviceNotificationsLinux::InitOnFileThread() { |
| 355 DCHECK(!initialized_); | 361 DCHECK(!initialized_); |
| 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 357 initialized_ = true; | 363 initialized_ = true; |
| 358 | 364 |
| 365 if (SystemMonitor::Get()) |
| 366 SystemMonitor::Get()->set_storage_free_space_delegate(this); |
| 367 |
| 359 // The callback passed to Watch() has to be unretained. Otherwise | 368 // The callback passed to Watch() has to be unretained. Otherwise |
| 360 // RemovableDeviceNotificationsLinux will live longer than expected, and | 369 // RemovableDeviceNotificationsLinux will live longer than expected, and |
| 361 // FilePathWatcher will get in trouble at shutdown time. | 370 // FilePathWatcher will get in trouble at shutdown time. |
| 362 bool ret = file_watcher_.Watch( | 371 bool ret = file_watcher_.Watch( |
| 363 mtab_path_, | 372 mtab_path_, |
| 364 base::Bind(&RemovableDeviceNotificationsLinux::OnFilePathChanged, | 373 base::Bind(&RemovableDeviceNotificationsLinux::OnFilePathChanged, |
| 365 base::Unretained(this))); | 374 base::Unretained(this))); |
| 366 if (!ret) { | 375 if (!ret) { |
| 367 LOG(ERROR) << "Adding watch for " << mtab_path_.value() << " failed"; | 376 LOG(ERROR) << "Adding watch for " << mtab_path_.value() << " failed"; |
| 368 return; | 377 return; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 508 |
| 500 mount_info_map_[mount_point] = mount_point_info; | 509 mount_info_map_[mount_point] = mount_point_info; |
| 501 mount_priority_map_[mount_device][mount_point] = removable; | 510 mount_priority_map_[mount_device][mount_point] = removable; |
| 502 | 511 |
| 503 if (removable) { | 512 if (removable) { |
| 504 SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, | 513 SystemMonitor::Get()->ProcessRemovableStorageAttached(device_id, name, |
| 505 mount_point.value()); | 514 mount_point.value()); |
| 506 } | 515 } |
| 507 } | 516 } |
| 508 | 517 |
| 518 void RemovableDeviceNotificationsLinux::StartWatchingStorage( |
| 519 const FilePath& path) { |
| 520 NOTIMPLEMENTED(); |
| 521 } |
| 522 |
| 523 void RemovableDeviceNotificationsLinux::StopWatchingStorage( |
| 524 const FilePath& path) { |
| 525 NOTIMPLEMENTED(); |
| 526 } |
| 527 |
| 509 } // namespace chrome | 528 } // namespace chrome |
| OLD | NEW |