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 |
11 namespace file_manager { | 11 namespace file_manager { |
12 namespace { | 12 namespace { |
13 namespace file_browser_private = extensions::api::file_browser_private; | 13 namespace file_manager_private = extensions::api::file_manager_private; |
14 using content::BrowserThread; | 14 using content::BrowserThread; |
15 } // namespace | 15 } // namespace |
16 | 16 |
17 DeviceEventRouter::DeviceEventRouter() | 17 DeviceEventRouter::DeviceEventRouter() |
18 : resume_time_delta_(base::TimeDelta::FromSeconds(5)), | 18 : resume_time_delta_(base::TimeDelta::FromSeconds(5)), |
19 startup_time_delta_(base::TimeDelta::FromSeconds(10)), | 19 startup_time_delta_(base::TimeDelta::FromSeconds(10)), |
20 scan_time_delta_(base::TimeDelta::FromSeconds(5)), | 20 scan_time_delta_(base::TimeDelta::FromSeconds(5)), |
21 is_starting_up_(false), | 21 is_starting_up_(false), |
22 is_resuming_(false), | 22 is_resuming_(false), |
23 weak_factory_(this) { | 23 weak_factory_(this) { |
(...skipping 27 matching lines...) Expand all Loading... |
51 | 51 |
52 void DeviceEventRouter::OnDeviceAdded(const std::string& device_path) { | 52 void DeviceEventRouter::OnDeviceAdded(const std::string& device_path) { |
53 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
54 | 54 |
55 if (is_starting_up_ || is_resuming_) { | 55 if (is_starting_up_ || is_resuming_) { |
56 SetDeviceState(device_path, DEVICE_STATE_USUAL); | 56 SetDeviceState(device_path, DEVICE_STATE_USUAL); |
57 return; | 57 return; |
58 } | 58 } |
59 | 59 |
60 if (IsExternalStorageDisabled()) { | 60 if (IsExternalStorageDisabled()) { |
61 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_DISABLED, | 61 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_DISABLED, |
62 device_path); | 62 device_path); |
63 SetDeviceState(device_path, DEVICE_STATE_USUAL); | 63 SetDeviceState(device_path, DEVICE_STATE_USUAL); |
64 return; | 64 return; |
65 } | 65 } |
66 | 66 |
67 SetDeviceState(device_path, DEVICE_SCANNED); | 67 SetDeviceState(device_path, DEVICE_SCANNED); |
68 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 68 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
69 FROM_HERE, | 69 FROM_HERE, |
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 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_SCAN_STARTED, | 80 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_SCAN_STARTED, |
81 device_path); | 81 device_path); |
82 SetDeviceState(device_path, DEVICE_SCANNED_AND_REPORTED); | 82 SetDeviceState(device_path, DEVICE_SCANNED_AND_REPORTED); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 void DeviceEventRouter::OnDeviceRemoved(const std::string& device_path) { | 86 void DeviceEventRouter::OnDeviceRemoved(const std::string& device_path) { |
87 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
88 SetDeviceState(device_path, DEVICE_STATE_USUAL); | 88 SetDeviceState(device_path, DEVICE_STATE_USUAL); |
89 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_REMOVED, device_path); | 89 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_REMOVED, device_path); |
90 } | 90 } |
91 | 91 |
92 void DeviceEventRouter::OnDiskAdded( | 92 void DeviceEventRouter::OnDiskAdded( |
93 const chromeos::disks::DiskMountManager::Disk& disk, | 93 const chromeos::disks::DiskMountManager::Disk& disk, |
94 bool mounting) { | 94 bool mounting) { |
95 DCHECK(thread_checker_.CalledOnValidThread()); | 95 DCHECK(thread_checker_.CalledOnValidThread()); |
96 | 96 |
97 if (!mounting) { | 97 if (!mounting) { |
98 // 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. |
99 const std::string& device_path = disk.system_path_prefix(); | 99 const std::string& device_path = disk.system_path_prefix(); |
100 if (GetDeviceState(device_path) == DEVICE_SCANNED_AND_REPORTED) { | 100 if (GetDeviceState(device_path) == DEVICE_SCANNED_AND_REPORTED) { |
101 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_SCAN_CANCELLED, | 101 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_SCAN_CANCELLED, |
102 device_path); | 102 device_path); |
103 } | 103 } |
104 SetDeviceState(device_path, DEVICE_STATE_USUAL); | 104 SetDeviceState(device_path, DEVICE_STATE_USUAL); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 void DeviceEventRouter::OnDiskRemoved( | 108 void DeviceEventRouter::OnDiskRemoved( |
109 const chromeos::disks::DiskMountManager::Disk& disk) { | 109 const chromeos::disks::DiskMountManager::Disk& disk) { |
110 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
111 | 111 |
112 if (is_resuming_ || is_starting_up_) | 112 if (is_resuming_ || is_starting_up_) |
113 return; | 113 return; |
114 | 114 |
115 const std::string& device_path = disk.system_path_prefix(); | 115 const std::string& device_path = disk.system_path_prefix(); |
116 if (!disk.mount_path().empty() && | 116 if (!disk.mount_path().empty() && |
117 GetDeviceState(device_path) != DEVICE_HARD_UNPLUGGED_AND_REPORTED) { | 117 GetDeviceState(device_path) != DEVICE_HARD_UNPLUGGED_AND_REPORTED) { |
118 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, | 118 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_HARD_UNPLUGGED, |
119 device_path); | 119 device_path); |
120 SetDeviceState(device_path, DEVICE_HARD_UNPLUGGED_AND_REPORTED); | 120 SetDeviceState(device_path, DEVICE_HARD_UNPLUGGED_AND_REPORTED); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void DeviceEventRouter::OnVolumeMounted(chromeos::MountError error_code, | 124 void DeviceEventRouter::OnVolumeMounted(chromeos::MountError error_code, |
125 const VolumeInfo& volume_info) { | 125 const VolumeInfo& volume_info) { |
126 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
127 | 127 |
128 const std::string& device_path = | 128 const std::string& device_path = |
129 volume_info.system_path_prefix.AsUTF8Unsafe(); | 129 volume_info.system_path_prefix.AsUTF8Unsafe(); |
130 SetDeviceState(device_path, DEVICE_STATE_USUAL); | 130 SetDeviceState(device_path, DEVICE_STATE_USUAL); |
131 } | 131 } |
132 | 132 |
133 void DeviceEventRouter::OnVolumeUnmounted(chromeos::MountError error_code, | 133 void DeviceEventRouter::OnVolumeUnmounted(chromeos::MountError error_code, |
134 const VolumeInfo& volume_info) { | 134 const VolumeInfo& volume_info) { |
135 // Do nothing. | 135 // Do nothing. |
136 } | 136 } |
137 | 137 |
138 void DeviceEventRouter::OnFormatStarted(const std::string& device_path, | 138 void DeviceEventRouter::OnFormatStarted(const std::string& device_path, |
139 bool success) { | 139 bool success) { |
140 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
141 | 141 |
142 if (success) { | 142 if (success) { |
143 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_FORMAT_START, | 143 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_FORMAT_START, |
144 device_path); | 144 device_path); |
145 } else { | 145 } else { |
146 OnDeviceEvent(file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | 146 OnDeviceEvent(file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, |
147 device_path); | 147 device_path); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 void DeviceEventRouter::OnFormatCompleted(const std::string& device_path, | 151 void DeviceEventRouter::OnFormatCompleted(const std::string& device_path, |
152 bool success) { | 152 bool success) { |
153 DCHECK(thread_checker_.CalledOnValidThread()); | 153 DCHECK(thread_checker_.CalledOnValidThread()); |
154 | 154 |
155 OnDeviceEvent(success ? file_browser_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS | 155 OnDeviceEvent(success ? file_manager_private::DEVICE_EVENT_TYPE_FORMAT_SUCCESS |
156 : file_browser_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, | 156 : file_manager_private::DEVICE_EVENT_TYPE_FORMAT_FAIL, |
157 device_path); | 157 device_path); |
158 } | 158 } |
159 | 159 |
160 void DeviceEventRouter::SuspendImminent() { | 160 void DeviceEventRouter::SuspendImminent() { |
161 DCHECK(thread_checker_.CalledOnValidThread()); | 161 DCHECK(thread_checker_.CalledOnValidThread()); |
162 is_resuming_ = true; | 162 is_resuming_ = true; |
163 } | 163 } |
164 | 164 |
165 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { | 165 void DeviceEventRouter::SuspendDone(const base::TimeDelta& sleep_duration) { |
166 DCHECK(thread_checker_.CalledOnValidThread()); | 166 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 22 matching lines...) Expand all Loading... |
189 device_states_[device_path] = state; | 189 device_states_[device_path] = state; |
190 } else { | 190 } else { |
191 const std::map<std::string, DeviceState>::iterator it = | 191 const std::map<std::string, DeviceState>::iterator it = |
192 device_states_.find(device_path); | 192 device_states_.find(device_path); |
193 if (it != device_states_.end()) | 193 if (it != device_states_.end()) |
194 device_states_.erase(it); | 194 device_states_.erase(it); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 } // namespace file_manager | 198 } // namespace file_manager |
OLD | NEW |