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_CUSTOM_TIMES("FileBrowser.HardUnpluggedAfterResume", | |
87 base::Time::Now() - last_suspend_done_, | |
88 base::TimeDelta::FromMilliseconds(1), | |
89 base::TimeDelta::FromSeconds(30), 50); | |
Alexei Svitkine (slow)
2014/11/25 17:48:12
Nit: I suggest using UMA_HISTOGRAM_MEDIUM_TIMES().
hirono
2014/12/02 08:52:43
Done.
| |
90 } | |
91 last_hard_unplugged_ = base::Time::Now(); | |
83 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, | 92 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, |
84 device_path); | 93 device_path); |
85 SetDeviceState(device_path, DEVICE_HARD_UNPLUGGED_AND_REPORTED); | 94 SetDeviceState(device_path, DEVICE_HARD_UNPLUGGED_AND_REPORTED); |
86 } | 95 } |
87 } | 96 } |
88 | 97 |
89 void DeviceEventRouter::OnVolumeMounted(chromeos::MountError error_code, | 98 void DeviceEventRouter::OnVolumeMounted(chromeos::MountError error_code, |
90 const VolumeInfo& volume_info) { | 99 const VolumeInfo& volume_info) { |
91 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
92 | 101 |
(...skipping 24 matching lines...) Expand all Loading... | |
117 bool success) { | 126 bool success) { |
118 DCHECK(thread_checker_.CalledOnValidThread()); | 127 DCHECK(thread_checker_.CalledOnValidThread()); |
119 | 128 |
120 OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS | 129 OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS |
121 : file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | 130 : file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, |
122 device_path); | 131 device_path); |
123 } | 132 } |
124 | 133 |
125 void DeviceEventRouter::SuspendImminent() { | 134 void DeviceEventRouter::SuspendImminent() { |
126 DCHECK(thread_checker_.CalledOnValidThread()); | 135 DCHECK(thread_checker_.CalledOnValidThread()); |
136 // TODO(hirono): Remove the temporary UMA. crbug.com/433734 | |
137 if (!last_hard_unplugged_.is_null()) { | |
138 UMA_HISTOGRAM_CUSTOM_TIMES("FileBrowser.HardUnpluggedBeforeSuspend", | |
139 base::Time::Now() - last_hard_unplugged_, | |
140 base::TimeDelta::FromMilliseconds(1), | |
141 base::TimeDelta::FromSeconds(30), 50); | |
142 } | |
127 is_resuming_ = true; | 143 is_resuming_ = true; |
128 } | 144 } |
129 | 145 |
130 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { | 146 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { |
131 DCHECK(thread_checker_.CalledOnValidThread()); | 147 DCHECK(thread_checker_.CalledOnValidThread()); |
148 last_suspend_done_ = base::Time::Now(); | |
132 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 149 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
133 FROM_HERE, | 150 FROM_HERE, |
134 base::Bind(&DeviceEventRouter::SuspendDoneDelayed, | 151 base::Bind(&DeviceEventRouter::SuspendDoneDelayed, |
135 weak_factory_.GetWeakPtr()), | 152 weak_factory_.GetWeakPtr()), |
136 resume_time_delta_); | 153 resume_time_delta_); |
137 } | 154 } |
138 | 155 |
139 void DeviceEventRouter::SuspendDoneDelayed() { | 156 void DeviceEventRouter::SuspendDoneDelayed() { |
140 DCHECK(thread_checker_.CalledOnValidThread()); | 157 DCHECK(thread_checker_.CalledOnValidThread()); |
141 is_resuming_ = false; | 158 is_resuming_ = false; |
(...skipping 12 matching lines...) Expand all Loading... | |
154 device_states_[device_path] = state; | 171 device_states_[device_path] = state; |
155 } else { | 172 } else { |
156 const std::map<std::string, DeviceState>::iterator it = | 173 const std::map<std::string, DeviceState>::iterator it = |
157 device_states_.find(device_path); | 174 device_states_.find(device_path); |
158 if (it != device_states_.end()) | 175 if (it != device_states_.end()) |
159 device_states_.erase(it); | 176 device_states_.erase(it); |
160 } | 177 } |
161 } | 178 } |
162 | 179 |
163 } // namespace file_manager | 180 } // namespace file_manager |
OLD | NEW |