OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "apps/shell_window_geometry_cache.h" | 5 #include "apps/shell_window_geometry_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 // Not in the map means loading data for the extension didn't finish yet or | 141 // Not in the map means loading data for the extension didn't finish yet or |
142 // the cache was not constructed until after the extension was loaded. | 142 // the cache was not constructed until after the extension was loaded. |
143 // Attempt to load from sync to address the latter case. | 143 // Attempt to load from sync to address the latter case. |
144 if (extension_data_it == cache_.end()) { | 144 if (extension_data_it == cache_.end()) { |
145 LoadGeometryFromStorage(extension_id); | 145 LoadGeometryFromStorage(extension_id); |
146 extension_data_it = cache_.find(extension_id); | 146 extension_data_it = cache_.find(extension_id); |
147 DCHECK(extension_data_it != cache_.end()); | 147 DCHECK(extension_data_it != cache_.end()); |
148 } | 148 } |
149 | 149 |
150 ExtensionData::const_iterator window_data = extension_data_it->second.find( | 150 ExtensionData::const_iterator window_data_it = extension_data_it->second.find( |
151 window_id); | 151 window_id); |
152 | 152 |
153 if (window_data == extension_data_it->second.end()) | 153 if (window_data_it == extension_data_it->second.end()) |
| 154 return false; |
| 155 |
| 156 const WindowData& window_data = window_data_it->second; |
| 157 |
| 158 // Check for and do not return corrupt data. |
| 159 if ((bounds && window_data.bounds.IsEmpty()) || |
| 160 (screen_bounds && window_data.screen_bounds.IsEmpty()) || |
| 161 (window_state && window_data.window_state == ui::SHOW_STATE_DEFAULT)) |
154 return false; | 162 return false; |
155 | 163 |
156 if (bounds) | 164 if (bounds) |
157 *bounds = window_data->second.bounds; | 165 *bounds = window_data.bounds; |
158 if (screen_bounds) | 166 if (screen_bounds) |
159 *screen_bounds = window_data->second.screen_bounds; | 167 *screen_bounds = window_data.screen_bounds; |
160 if (window_state) | 168 if (window_state) |
161 *window_state = window_data->second.window_state; | 169 *window_state = window_data.window_state; |
162 return true; | 170 return true; |
163 } | 171 } |
164 | 172 |
165 void ShellWindowGeometryCache::Shutdown() { | 173 void ShellWindowGeometryCache::Shutdown() { |
166 SyncToStorage(); | 174 SyncToStorage(); |
167 } | 175 } |
168 | 176 |
169 | 177 |
170 ShellWindowGeometryCache::WindowData::WindowData() | 178 ShellWindowGeometryCache::WindowData::WindowData() |
171 : window_state(ui::SHOW_STATE_DEFAULT) { | 179 : window_state(ui::SHOW_STATE_DEFAULT) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 return false; | 307 return false; |
300 } | 308 } |
301 | 309 |
302 content::BrowserContext* | 310 content::BrowserContext* |
303 ShellWindowGeometryCache::Factory::GetBrowserContextToUse( | 311 ShellWindowGeometryCache::Factory::GetBrowserContextToUse( |
304 content::BrowserContext* context) const { | 312 content::BrowserContext* context) const { |
305 return chrome::GetBrowserContextRedirectedInIncognito(context); | 313 return chrome::GetBrowserContextRedirectedInIncognito(context); |
306 } | 314 } |
307 | 315 |
308 } // namespace apps | 316 } // namespace apps |
OLD | NEW |