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/thread_task_runner_handle.h" | 6 #include "base/thread_task_runner_handle.h" |
7 #include "chrome/browser/chromeos/extensions/file_manager/device_event_router.h" | 7 #include "chrome/browser/chromeos/extensions/file_manager/device_event_router.h" |
8 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 8 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 base::Bind(&DeviceEventRouter::OnDeviceAddedDelayed, | 70 base::Bind(&DeviceEventRouter::OnDeviceAddedDelayed, |
71 weak_factory_.GetWeakPtr(), | 71 weak_factory_.GetWeakPtr(), |
72 device_path), | 72 device_path), |
73 scan_time_delta_); | 73 scan_time_delta_); |
74 } | 74 } |
75 | 75 |
76 void DeviceEventRouter::OnDeviceAddedDelayed(const std::string& device_path) { | 76 void DeviceEventRouter::OnDeviceAddedDelayed(const std::string& device_path) { |
77 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
78 | 78 |
79 if (GetDeviceState(device_path) == DEVICE_SCANNED) { | 79 if (GetDeviceState(device_path) == DEVICE_SCANNED) { |
80 // TODO(hirono): Rename DEVICE_EVENT_TYPE_ADDED with | 80 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_SCAN_STARTED, |
81 // DEVICE_EVENT_TYPE_SCAN_STARTED. | 81 device_path); |
82 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_ADDED, device_path); | |
83 SetDeviceState(device_path, DEVICE_SCANNED_AND_REPORTED); | 82 SetDeviceState(device_path, DEVICE_SCANNED_AND_REPORTED); |
84 } | 83 } |
85 } | 84 } |
86 | 85 |
87 void DeviceEventRouter::OnDeviceRemoved(const std::string& device_path) { | 86 void DeviceEventRouter::OnDeviceRemoved(const std::string& device_path) { |
88 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
89 SetDeviceState(device_path, DEVICE_STATE_USUAL); | 88 SetDeviceState(device_path, DEVICE_STATE_USUAL); |
90 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, device_path); | 89 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, device_path); |
91 } | 90 } |
92 | 91 |
93 void DeviceEventRouter::OnDiskAdded( | 92 void DeviceEventRouter::OnDiskAdded( |
94 const chromeos::disks::DiskMountManager::Disk& disk, | 93 const chromeos::disks::DiskMountManager::Disk& disk, |
95 bool mounting) { | 94 bool mounting) { |
96 DCHECK(thread_checker_.CalledOnValidThread()); | 95 DCHECK(thread_checker_.CalledOnValidThread()); |
97 | 96 |
98 if (!mounting) { | 97 if (!mounting) { |
99 // If the disk is not being mounted, mark the device scan cancelled. | 98 // If the disk is not being mounted, mark the device scan cancelled. |
100 const std::string& device_path = disk.system_path_prefix(); | 99 const std::string& device_path = disk.system_path_prefix(); |
101 if (GetDeviceState(device_path) == DEVICE_SCANNED_AND_REPORTED) { | 100 if (GetDeviceState(device_path) == DEVICE_SCANNED_AND_REPORTED) { |
102 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_SCAN_CANCELED, | 101 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_SCAN_CANCELLED, |
103 device_path); | 102 device_path); |
104 } | 103 } |
105 SetDeviceState(device_path, DEVICE_STATE_USUAL); | 104 SetDeviceState(device_path, DEVICE_STATE_USUAL); |
106 } | 105 } |
107 } | 106 } |
108 | 107 |
109 void DeviceEventRouter::OnDiskRemoved( | 108 void DeviceEventRouter::OnDiskRemoved( |
110 const chromeos::disks::DiskMountManager::Disk& disk) { | 109 const chromeos::disks::DiskMountManager::Disk& disk) { |
111 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
112 | 111 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 151 |
153 void DeviceEventRouter::OnFormatCompleted(const std::string& device_path, | 152 void DeviceEventRouter::OnFormatCompleted(const std::string& device_path, |
154 bool success) { | 153 bool success) { |
155 DCHECK(thread_checker_.CalledOnValidThread()); | 154 DCHECK(thread_checker_.CalledOnValidThread()); |
156 | 155 |
157 OnDeviceEvent(success ? file_browser_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS | 156 OnDeviceEvent(success ? file_browser_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS |
158 : file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | 157 : file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, |
159 device_path); | 158 device_path); |
160 } | 159 } |
161 | 160 |
162 void DeviceEventRouter::OnHardUnplugged(const std::string& device_path) { | |
163 } | |
164 | |
165 void DeviceEventRouter::SuspendImminent() { | 161 void DeviceEventRouter::SuspendImminent() { |
166 DCHECK(thread_checker_.CalledOnValidThread()); | 162 DCHECK(thread_checker_.CalledOnValidThread()); |
167 is_resuming_ = true; | 163 is_resuming_ = true; |
168 } | 164 } |
169 | 165 |
170 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { | 166 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { |
171 DCHECK(thread_checker_.CalledOnValidThread()); | 167 DCHECK(thread_checker_.CalledOnValidThread()); |
172 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 168 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
173 FROM_HERE, | 169 FROM_HERE, |
174 base::Bind(&DeviceEventRouter::SuspendDoneDelayed, | 170 base::Bind(&DeviceEventRouter::SuspendDoneDelayed, |
(...skipping 19 matching lines...) Expand all Loading... |
194 device_states_[device_path] = state; | 190 device_states_[device_path] = state; |
195 } else { | 191 } else { |
196 const std::map<std::string, DeviceState>::iterator it = | 192 const std::map<std::string, DeviceState>::iterator it = |
197 device_states_.find(device_path); | 193 device_states_.find(device_path); |
198 if (it != device_states_.end()) | 194 if (it != device_states_.end()) |
199 device_states_.erase(it); | 195 device_states_.erase(it); |
200 } | 196 } |
201 } | 197 } |
202 | 198 |
203 } // namespace file_manager | 199 } // namespace file_manager |
OLD | NEW |