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