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