OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/metrics/histogram_macros.h" |
6 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
7 #include "chrome/browser/chromeos/extensions/file_manager/device_event_router.h" | 8 #include "chrome/browser/chromeos/extensions/file_manager/device_event_router.h" |
8 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 9 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 | 11 |
11 namespace file_manager { | 12 namespace file_manager { |
12 namespace { | 13 namespace { |
13 namespace file_manager_private = extensions::api::file_manager_private; | 14 namespace file_manager_private = extensions::api::file_manager_private; |
14 using content::BrowserThread; | 15 using content::BrowserThread; |
15 } // namespace | 16 } // namespace |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 void DeviceEventRouter::OnDiskRemoved( | 74 void DeviceEventRouter::OnDiskRemoved( |
74 const chromeos::disks::DiskMountManager::Disk& disk) { | 75 const chromeos::disks::DiskMountManager::Disk& disk) { |
75 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
76 | 77 |
77 if (is_resuming_ || is_starting_up_) | 78 if (is_resuming_ || is_starting_up_) |
78 return; | 79 return; |
79 | 80 |
80 const std::string& device_path = disk.system_path_prefix(); | 81 const std::string& device_path = disk.system_path_prefix(); |
81 if (!disk.mount_path().empty() && | 82 if (!disk.mount_path().empty() && |
82 GetDeviceState(device_path) != DEVICE_HARD_UNPLUGGED_AND_REPORTED) { | 83 GetDeviceState(device_path) != DEVICE_HARD_UNPLUGGED_AND_REPORTED) { |
| 84 // TODO(hirono): Remove the temporary UMA. crbug.com/433734 |
| 85 if (!last_suspend_done_.is_null()) { |
| 86 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 87 "FileBrowser.HardUnpluggedAroundSuspend.TimeSinceResume", |
| 88 base::Time::Now() - last_suspend_done_); |
| 89 } |
| 90 last_hard_unplugged_ = base::Time::Now(); |
83 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, | 91 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, |
84 device_path); | 92 device_path); |
85 SetDeviceState(device_path, DEVICE_HARD_UNPLUGGED_AND_REPORTED); | 93 SetDeviceState(device_path, DEVICE_HARD_UNPLUGGED_AND_REPORTED); |
86 } | 94 } |
87 } | 95 } |
88 | 96 |
89 void DeviceEventRouter::OnVolumeMounted(chromeos::MountError error_code, | 97 void DeviceEventRouter::OnVolumeMounted(chromeos::MountError error_code, |
90 const VolumeInfo& volume_info) { | 98 const VolumeInfo& volume_info) { |
91 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
92 | 100 |
(...skipping 24 matching lines...) Expand all Loading... |
117 bool success) { | 125 bool success) { |
118 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
119 | 127 |
120 OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS | 128 OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS |
121 : file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | 129 : file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, |
122 device_path); | 130 device_path); |
123 } | 131 } |
124 | 132 |
125 void DeviceEventRouter::SuspendImminent() { | 133 void DeviceEventRouter::SuspendImminent() { |
126 DCHECK(thread_checker_.CalledOnValidThread()); | 134 DCHECK(thread_checker_.CalledOnValidThread()); |
| 135 // TODO(hirono): Remove the temporary UMA. crbug.com/433734 |
| 136 if (!last_hard_unplugged_.is_null()) { |
| 137 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 138 "FileBrowser.HardUnpluggedAroundSuspend.TimeUntilSuspend", |
| 139 base::Time::Now() - last_hard_unplugged_); |
| 140 } |
127 is_resuming_ = true; | 141 is_resuming_ = true; |
128 } | 142 } |
129 | 143 |
130 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { | 144 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { |
131 DCHECK(thread_checker_.CalledOnValidThread()); | 145 DCHECK(thread_checker_.CalledOnValidThread()); |
| 146 last_suspend_done_ = base::Time::Now(); |
132 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 147 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
133 FROM_HERE, | 148 FROM_HERE, |
134 base::Bind(&DeviceEventRouter::SuspendDoneDelayed, | 149 base::Bind(&DeviceEventRouter::SuspendDoneDelayed, |
135 weak_factory_.GetWeakPtr()), | 150 weak_factory_.GetWeakPtr()), |
136 resume_time_delta_); | 151 resume_time_delta_); |
137 } | 152 } |
138 | 153 |
139 void DeviceEventRouter::SuspendDoneDelayed() { | 154 void DeviceEventRouter::SuspendDoneDelayed() { |
140 DCHECK(thread_checker_.CalledOnValidThread()); | 155 DCHECK(thread_checker_.CalledOnValidThread()); |
141 is_resuming_ = false; | 156 is_resuming_ = false; |
(...skipping 12 matching lines...) Expand all Loading... |
154 device_states_[device_path] = state; | 169 device_states_[device_path] = state; |
155 } else { | 170 } else { |
156 const std::map<std::string, DeviceState>::iterator it = | 171 const std::map<std::string, DeviceState>::iterator it = |
157 device_states_.find(device_path); | 172 device_states_.find(device_path); |
158 if (it != device_states_.end()) | 173 if (it != device_states_.end()) |
159 device_states_.erase(it); | 174 device_states_.erase(it); |
160 } | 175 } |
161 } | 176 } |
162 | 177 |
163 } // namespace file_manager | 178 } // namespace file_manager |
OLD | NEW |