Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: apps/saved_files_service.cc

Issue 1851373002: convert //apps to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « apps/saved_files_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/saved_files_service.h" 5 #include "apps/saved_files_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 11
12 #include "apps/saved_files_service_factory.h" 12 #include "apps/saved_files_service_factory.h"
13 #include "base/containers/scoped_ptr_hash_map.h" 13 #include "base/containers/scoped_ptr_hash_map.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/value_conversions.h" 15 #include "base/value_conversions.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "content/public/browser/notification_service.h" 18 #include "content/public/browser/notification_service.h"
18 #include "extensions/browser/extension_host.h" 19 #include "extensions/browser/extension_host.h"
19 #include "extensions/browser/extension_prefs.h" 20 #include "extensions/browser/extension_prefs.h"
20 #include "extensions/browser/extension_system.h" 21 #include "extensions/browser/extension_system.h"
21 #include "extensions/browser/notification_types.h" 22 #include "extensions/browser/notification_types.h"
22 #include "extensions/common/permissions/api_permission.h" 23 #include "extensions/common/permissions/api_permission.h"
23 #include "extensions/common/permissions/permission_set.h" 24 #include "extensions/common/permissions/permission_set.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // will almost never do any real work. 172 // will almost never do any real work.
172 void MaybeCompactSequenceNumbers(); 173 void MaybeCompactSequenceNumbers();
173 174
174 void LoadSavedFileEntriesFromPreferences(); 175 void LoadSavedFileEntriesFromPreferences();
175 176
176 Profile* profile_; 177 Profile* profile_;
177 const std::string extension_id_; 178 const std::string extension_id_;
178 179
179 // Contains all file entries that have been registered, keyed by ID. Owns 180 // Contains all file entries that have been registered, keyed by ID. Owns
180 // values. 181 // values.
181 base::ScopedPtrHashMap<std::string, scoped_ptr<SavedFileEntry>> 182 base::ScopedPtrHashMap<std::string, std::unique_ptr<SavedFileEntry>>
182 registered_file_entries_; 183 registered_file_entries_;
183 184
184 // The queue of file entries that have been retained, keyed by 185 // The queue of file entries that have been retained, keyed by
185 // sequence_number. Values are a subset of values in registered_file_entries_. 186 // sequence_number. Values are a subset of values in registered_file_entries_.
186 // This should be kept in sync with file entries stored in extension prefs. 187 // This should be kept in sync with file entries stored in extension prefs.
187 std::map<int, SavedFileEntry*> saved_file_lru_; 188 std::map<int, SavedFileEntry*> saved_file_lru_;
188 189
189 DISALLOW_COPY_AND_ASSIGN(SavedFiles); 190 DISALLOW_COPY_AND_ASSIGN(SavedFiles);
190 }; 191 };
191 192
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 281
281 return NULL; 282 return NULL;
282 } 283 }
283 284
284 SavedFilesService::SavedFiles* SavedFilesService::GetOrInsert( 285 SavedFilesService::SavedFiles* SavedFilesService::GetOrInsert(
285 const std::string& extension_id) { 286 const std::string& extension_id) {
286 SavedFiles* saved_files = Get(extension_id); 287 SavedFiles* saved_files = Get(extension_id);
287 if (saved_files) 288 if (saved_files)
288 return saved_files; 289 return saved_files;
289 290
290 scoped_ptr<SavedFiles> scoped_saved_files( 291 std::unique_ptr<SavedFiles> scoped_saved_files(
291 new SavedFiles(profile_, extension_id)); 292 new SavedFiles(profile_, extension_id));
292 saved_files = scoped_saved_files.get(); 293 saved_files = scoped_saved_files.get();
293 extension_id_to_saved_files_.insert( 294 extension_id_to_saved_files_.insert(
294 std::make_pair(extension_id, std::move(scoped_saved_files))); 295 std::make_pair(extension_id, std::move(scoped_saved_files)));
295 return saved_files; 296 return saved_files;
296 } 297 }
297 298
298 void SavedFilesService::Clear(const std::string& extension_id) { 299 void SavedFilesService::Clear(const std::string& extension_id) {
299 extension_id_to_saved_files_.erase(extension_id); 300 extension_id_to_saved_files_.erase(extension_id);
300 } 301 }
301 302
302 SavedFilesService::SavedFiles::SavedFiles(Profile* profile, 303 SavedFilesService::SavedFiles::SavedFiles(Profile* profile,
303 const std::string& extension_id) 304 const std::string& extension_id)
304 : profile_(profile), extension_id_(extension_id) { 305 : profile_(profile), extension_id_(extension_id) {
305 LoadSavedFileEntriesFromPreferences(); 306 LoadSavedFileEntriesFromPreferences();
306 } 307 }
307 308
308 SavedFilesService::SavedFiles::~SavedFiles() {} 309 SavedFilesService::SavedFiles::~SavedFiles() {}
309 310
310 void SavedFilesService::SavedFiles::RegisterFileEntry( 311 void SavedFilesService::SavedFiles::RegisterFileEntry(
311 const std::string& id, 312 const std::string& id,
312 const base::FilePath& file_path, 313 const base::FilePath& file_path,
313 bool is_directory) { 314 bool is_directory) {
314 if (ContainsKey(registered_file_entries_, id)) 315 if (ContainsKey(registered_file_entries_, id))
315 return; 316 return;
316 317
317 registered_file_entries_.add( 318 registered_file_entries_.add(
318 id, make_scoped_ptr(new SavedFileEntry(id, file_path, is_directory, 0))); 319 id, base::WrapUnique(new SavedFileEntry(id, file_path, is_directory, 0)));
319 } 320 }
320 321
321 void SavedFilesService::SavedFiles::EnqueueFileEntry(const std::string& id) { 322 void SavedFilesService::SavedFiles::EnqueueFileEntry(const std::string& id) {
322 auto it = registered_file_entries_.find(id); 323 auto it = registered_file_entries_.find(id);
323 DCHECK(it != registered_file_entries_.end()); 324 DCHECK(it != registered_file_entries_.end());
324 325
325 SavedFileEntry* file_entry = it->second; 326 SavedFileEntry* file_entry = it->second;
326 int old_sequence_number = file_entry->sequence_number; 327 int old_sequence_number = file_entry->sequence_number;
327 if (!saved_file_lru_.empty()) { 328 if (!saved_file_lru_.empty()) {
328 // Get the sequence number after the last file entry in the LRU. 329 // Get the sequence number after the last file entry in the LRU.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 413 }
413 } 414 }
414 415
415 void SavedFilesService::SavedFiles::LoadSavedFileEntriesFromPreferences() { 416 void SavedFilesService::SavedFiles::LoadSavedFileEntriesFromPreferences() {
416 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); 417 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
417 std::vector<SavedFileEntry> saved_entries = 418 std::vector<SavedFileEntry> saved_entries =
418 GetSavedFileEntries(prefs, extension_id_); 419 GetSavedFileEntries(prefs, extension_id_);
419 for (std::vector<SavedFileEntry>::iterator it = saved_entries.begin(); 420 for (std::vector<SavedFileEntry>::iterator it = saved_entries.begin();
420 it != saved_entries.end(); 421 it != saved_entries.end();
421 ++it) { 422 ++it) {
422 scoped_ptr<SavedFileEntry> file_entry(new SavedFileEntry(*it)); 423 std::unique_ptr<SavedFileEntry> file_entry(new SavedFileEntry(*it));
423 const std::string& id = file_entry->id; 424 const std::string& id = file_entry->id;
424 saved_file_lru_.insert( 425 saved_file_lru_.insert(
425 std::make_pair(file_entry->sequence_number, file_entry.get())); 426 std::make_pair(file_entry->sequence_number, file_entry.get()));
426 registered_file_entries_.add(id, std::move(file_entry)); 427 registered_file_entries_.add(id, std::move(file_entry));
427 } 428 }
428 } 429 }
429 430
430 // static 431 // static
431 void SavedFilesService::SetMaxSequenceNumberForTest(int max_value) { 432 void SavedFilesService::SetMaxSequenceNumberForTest(int max_value) {
432 g_max_sequence_number = max_value; 433 g_max_sequence_number = max_value;
433 } 434 }
434 435
435 // static 436 // static
436 void SavedFilesService::ClearMaxSequenceNumberForTest() { 437 void SavedFilesService::ClearMaxSequenceNumberForTest() {
437 g_max_sequence_number = kMaxSequenceNumber; 438 g_max_sequence_number = kMaxSequenceNumber;
438 } 439 }
439 440
440 // static 441 // static
441 void SavedFilesService::SetLruSizeForTest(int size) { 442 void SavedFilesService::SetLruSizeForTest(int size) {
442 g_max_saved_file_entries = size; 443 g_max_saved_file_entries = size;
443 } 444 }
444 445
445 // static 446 // static
446 void SavedFilesService::ClearLruSizeForTest() { 447 void SavedFilesService::ClearLruSizeForTest() {
447 g_max_saved_file_entries = kMaxSavedFileEntries; 448 g_max_saved_file_entries = kMaxSavedFileEntries;
448 } 449 }
449 450
450 } // namespace apps 451 } // namespace apps
OLDNEW
« no previous file with comments | « apps/saved_files_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698