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_album_table_reader.
h" | 5 #include "chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.
h" |
6 | 6 |
| 7 #include "base/logging.h" |
7 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 8 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
8 #include "chrome/common/chrome_utility_messages.h" | 9 #include "chrome/common/chrome_utility_messages.h" |
9 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/child_process_data.h" | 11 #include "content/public/browser/child_process_data.h" |
11 | 12 |
12 using chrome::MediaFileSystemBackend; | 13 using chrome::MediaFileSystemBackend; |
13 using content::BrowserThread; | 14 using content::BrowserThread; |
14 | 15 |
15 namespace picasa { | 16 namespace picasa { |
16 | 17 |
17 SafePicasaAlbumTableReader::SafePicasaAlbumTableReader( | 18 SafePicasaAlbumTableReader::SafePicasaAlbumTableReader( |
18 const AlbumTableFiles& album_table_files, | 19 const AlbumTableFiles& album_table_files, |
19 const ParserCallback& callback) | 20 const ParserCallback& callback) |
20 : album_table_files_(album_table_files), | 21 : album_table_files_(album_table_files), |
21 callback_(callback), | 22 callback_(callback), |
22 parser_state_(INITIAL_STATE) { | 23 parser_state_(INITIAL_STATE) { |
23 // TODO(tommycli): Add DCHECK to make sure |album_table_files| are all | 24 // TODO(tommycli): Add DCHECK to make sure |album_table_files| are all |
24 // opened read-only once security adds ability to check PlatformFiles. | 25 // opened read-only once security adds ability to check PlatformFiles. |
25 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 26 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
26 DCHECK(!callback_.is_null()); | 27 DCHECK(!callback_.is_null()); |
27 } | 28 } |
28 | 29 |
29 void SafePicasaAlbumTableReader::Start() { | 30 void SafePicasaAlbumTableReader::Start() { |
30 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 31 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 32 |
| 33 // Don't bother spawning process if any of the files are invalid. |
| 34 if (album_table_files_.indicator_file == base::kInvalidPlatformFileValue || |
| 35 album_table_files_.category_file == base::kInvalidPlatformFileValue || |
| 36 album_table_files_.date_file == base::kInvalidPlatformFileValue || |
| 37 album_table_files_.filename_file == base::kInvalidPlatformFileValue || |
| 38 album_table_files_.name_file == base::kInvalidPlatformFileValue || |
| 39 album_table_files_.token_file == base::kInvalidPlatformFileValue || |
| 40 album_table_files_.uid_file == base::kInvalidPlatformFileValue) { |
| 41 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
| 42 FROM_HERE, |
| 43 base::Bind(callback_, |
| 44 make_scoped_refptr(this), |
| 45 false /* parse_success */, |
| 46 std::vector<AlbumInfo>(), |
| 47 std::vector<AlbumInfo>())); |
| 48 return; |
| 49 } |
| 50 |
31 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
32 BrowserThread::IO, | 52 BrowserThread::IO, |
33 FROM_HERE, | 53 FROM_HERE, |
34 base::Bind(&SafePicasaAlbumTableReader::StartWorkOnIOThread, this)); | 54 base::Bind(&SafePicasaAlbumTableReader::StartWorkOnIOThread, this)); |
35 } | 55 } |
36 | 56 |
37 SafePicasaAlbumTableReader::~SafePicasaAlbumTableReader() { | 57 SafePicasaAlbumTableReader::~SafePicasaAlbumTableReader() { |
38 } | 58 } |
39 | 59 |
40 void SafePicasaAlbumTableReader::StartWorkOnIOThread() { | 60 void SafePicasaAlbumTableReader::StartWorkOnIOThread() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 void SafePicasaAlbumTableReader::OnParsePicasaPMPDatabaseFinished( | 116 void SafePicasaAlbumTableReader::OnParsePicasaPMPDatabaseFinished( |
97 bool parse_success, | 117 bool parse_success, |
98 const std::vector<AlbumInfo>& albums, | 118 const std::vector<AlbumInfo>& albums, |
99 const std::vector<AlbumInfo>& folders) { | 119 const std::vector<AlbumInfo>& folders) { |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
101 if (parser_state_ != STARTED_PARSING_STATE) | 121 if (parser_state_ != STARTED_PARSING_STATE) |
102 return; | 122 return; |
103 | 123 |
104 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 124 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
105 FROM_HERE, | 125 FROM_HERE, |
106 base::Bind(callback_, parse_success, albums, folders)); | 126 base::Bind( |
| 127 callback_, make_scoped_refptr(this), parse_success, albums, folders)); |
107 parser_state_ = FINISHED_PARSING_STATE; | 128 parser_state_ = FINISHED_PARSING_STATE; |
108 } | 129 } |
109 | 130 |
110 void SafePicasaAlbumTableReader::OnProcessCrashed(int exit_code) { | 131 void SafePicasaAlbumTableReader::OnProcessCrashed(int exit_code) { |
111 OnParsePicasaPMPDatabaseFinished(false, std::vector<AlbumInfo>(), | 132 DLOG(INFO) << "SafePicasaAlbumTableReader::OnProcessCrashed()"; |
112 std::vector<AlbumInfo>()); | 133 OnParsePicasaPMPDatabaseFinished( |
| 134 false, std::vector<AlbumInfo>(), std::vector<AlbumInfo>()); |
113 } | 135 } |
114 | 136 |
115 bool SafePicasaAlbumTableReader::OnMessageReceived( | 137 bool SafePicasaAlbumTableReader::OnMessageReceived( |
116 const IPC::Message& message) { | 138 const IPC::Message& message) { |
117 bool handled = true; | 139 bool handled = true; |
118 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumTableReader, message) | 140 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumTableReader, message) |
119 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, | 141 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, |
120 OnProcessStarted) | 142 OnProcessStarted) |
121 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished, | 143 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished, |
122 OnParsePicasaPMPDatabaseFinished) | 144 OnParsePicasaPMPDatabaseFinished) |
123 IPC_MESSAGE_UNHANDLED(handled = false) | 145 IPC_MESSAGE_UNHANDLED(handled = false) |
124 IPC_END_MESSAGE_MAP() | 146 IPC_END_MESSAGE_MAP() |
125 return handled; | 147 return handled; |
126 } | 148 } |
127 | 149 |
128 } // namespace picasa | 150 } // namespace picasa |
OLD | NEW |