OLD | NEW |
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 "chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h" | 5 #include "chrome/browser/media_galleries/fileapi/safe_picasa_albums_indexer.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 10 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 // Picasa INI files are named "picasa.ini" on Picasa for Windows before version | 30 // Picasa INI files are named "picasa.ini" on Picasa for Windows before version |
31 // 71.18. Later versions and Picasa for Mac uses ".picasa.ini". | 31 // 71.18. Later versions and Picasa for Mac uses ".picasa.ini". |
32 // See: https://support.google.com/picasa/answer/11257?hl=en | 32 // See: https://support.google.com/picasa/answer/11257?hl=en |
33 const char kPicasaINIFilenameLegacy[] = "picasa.ini"; | 33 const char kPicasaINIFilenameLegacy[] = "picasa.ini"; |
34 | 34 |
35 SafePicasaAlbumsIndexer::SafePicasaAlbumsIndexer(const AlbumMap& albums, | 35 SafePicasaAlbumsIndexer::SafePicasaAlbumsIndexer(const AlbumMap& albums, |
36 const AlbumMap& folders) | 36 const AlbumMap& folders) |
37 : parser_state_(INITIAL_STATE) { | 37 : parser_state_(INITIAL_STATE) { |
38 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 38 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
39 | 39 |
40 folders_inis_.reserve(folders.size()); | 40 folders_inis_.reserve(folders.size()); |
41 | 41 |
42 for (AlbumMap::const_iterator it = albums.begin(); it != albums.end(); ++it) | 42 for (AlbumMap::const_iterator it = albums.begin(); it != albums.end(); ++it) |
43 album_uids_.insert(it->second.uid); | 43 album_uids_.insert(it->second.uid); |
44 | 44 |
45 for (AlbumMap::const_iterator it = folders.begin(); it != folders.end(); ++it) | 45 for (AlbumMap::const_iterator it = folders.begin(); it != folders.end(); ++it) |
46 folders_queue_.push(it->second.path); | 46 folders_queue_.push(it->second.path); |
47 } | 47 } |
48 | 48 |
49 void SafePicasaAlbumsIndexer::Start(const DoneCallback& callback) { | 49 void SafePicasaAlbumsIndexer::Start(const DoneCallback& callback) { |
50 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 50 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
51 DCHECK(!callback.is_null()); | 51 DCHECK(!callback.is_null()); |
52 | 52 |
53 callback_ = callback; | 53 callback_ = callback; |
54 ProcessFoldersBatch(); | 54 ProcessFoldersBatch(); |
55 } | 55 } |
56 | 56 |
57 SafePicasaAlbumsIndexer::~SafePicasaAlbumsIndexer() { | 57 SafePicasaAlbumsIndexer::~SafePicasaAlbumsIndexer() { |
58 } | 58 } |
59 | 59 |
60 void SafePicasaAlbumsIndexer::ProcessFoldersBatch() { | 60 void SafePicasaAlbumsIndexer::ProcessFoldersBatch() { |
61 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 61 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
62 | 62 |
63 for (int i = 0; i < kPicasaINIReadBatchSize && !folders_queue_.empty(); ++i) { | 63 for (int i = 0; i < kPicasaINIReadBatchSize && !folders_queue_.empty(); ++i) { |
64 base::FilePath folder_path = folders_queue_.front(); | 64 base::FilePath folder_path = folders_queue_.front(); |
65 folders_queue_.pop(); | 65 folders_queue_.pop(); |
66 | 66 |
67 folders_inis_.push_back(FolderINIContents()); | 67 folders_inis_.push_back(FolderINIContents()); |
68 | 68 |
69 bool ini_read = | 69 bool ini_read = |
70 base::ReadFileToString( | 70 base::ReadFileToString( |
71 folder_path.AppendASCII(kPicasaINIFilename), | 71 folder_path.AppendASCII(kPicasaINIFilename), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumsIndexer, message) | 135 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumsIndexer, message) |
136 IPC_MESSAGE_HANDLER( | 136 IPC_MESSAGE_HANDLER( |
137 ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished, | 137 ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished, |
138 OnIndexPicasaAlbumsContentsFinished) | 138 OnIndexPicasaAlbumsContentsFinished) |
139 IPC_MESSAGE_UNHANDLED(handled = false) | 139 IPC_MESSAGE_UNHANDLED(handled = false) |
140 IPC_END_MESSAGE_MAP() | 140 IPC_END_MESSAGE_MAP() |
141 return handled; | 141 return handled; |
142 } | 142 } |
143 | 143 |
144 } // namespace picasa | 144 } // namespace picasa |
OLD | NEW |