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

Side by Side Diff: chrome/browser/media_galleries/fileapi/safe_picasa_album_table_reader.cc

Issue 18986012: Media Galleries API Picasa: Make PicasaDataProvider handle async PMP and INI parsing robustly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0039-picasa-import-sandbox-ini-parsing
Patch Set: update comment Created 7 years, 3 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
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 "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/bind.h"
8 #include "base/logging.h"
7 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 9 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
8 #include "chrome/common/chrome_utility_messages.h" 10 #include "chrome/common/chrome_utility_messages.h"
9 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/child_process_data.h" 12 #include "content/public/browser/child_process_data.h"
11 13
12 using chrome::MediaFileSystemBackend; 14 using chrome::MediaFileSystemBackend;
13 using content::BrowserThread; 15 using content::BrowserThread;
14 16
15 namespace picasa { 17 namespace picasa {
16 18
17 SafePicasaAlbumTableReader::SafePicasaAlbumTableReader( 19 SafePicasaAlbumTableReader::SafePicasaAlbumTableReader(
18 const AlbumTableFiles& album_table_files, 20 const AlbumTableFiles& album_table_files)
19 const ParserCallback& callback) 21 : album_table_files_(album_table_files), parser_state_(INITIAL_STATE) {
20 : album_table_files_(album_table_files),
21 callback_(callback),
22 parser_state_(INITIAL_STATE) {
23 // TODO(tommycli): Add DCHECK to make sure |album_table_files| are all 22 // TODO(tommycli): Add DCHECK to make sure |album_table_files| are all
24 // opened read-only once security adds ability to check PlatformFiles. 23 // opened read-only once security adds ability to check PlatformFiles.
25 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 24 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
26 DCHECK(!callback_.is_null());
27 } 25 }
28 26
29 void SafePicasaAlbumTableReader::Start() { 27 void SafePicasaAlbumTableReader::Start(const ParserCallback& callback) {
30 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); 28 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread());
29 DCHECK(!callback.is_null());
30
31 callback_ = callback;
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 false /* parse_success */,
45 std::vector<AlbumInfo>(),
46 std::vector<AlbumInfo>()));
47 return;
48 }
49
31 BrowserThread::PostTask( 50 BrowserThread::PostTask(
32 BrowserThread::IO, 51 BrowserThread::IO,
33 FROM_HERE, 52 FROM_HERE,
34 base::Bind(&SafePicasaAlbumTableReader::StartWorkOnIOThread, this)); 53 base::Bind(&SafePicasaAlbumTableReader::StartWorkOnIOThread, this));
35 } 54 }
36 55
37 SafePicasaAlbumTableReader::~SafePicasaAlbumTableReader() { 56 SafePicasaAlbumTableReader::~SafePicasaAlbumTableReader() {
38 } 57 }
39 58
40 void SafePicasaAlbumTableReader::StartWorkOnIOThread() { 59 void SafePicasaAlbumTableReader::StartWorkOnIOThread() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 utility_process_host_->Send(new ChromeUtilityMsg_ParsePicasaPMPDatabase( 110 utility_process_host_->Send(new ChromeUtilityMsg_ParsePicasaPMPDatabase(
92 files_for_transit)); 111 files_for_transit));
93 parser_state_ = STARTED_PARSING_STATE; 112 parser_state_ = STARTED_PARSING_STATE;
94 } 113 }
95 114
96 void SafePicasaAlbumTableReader::OnParsePicasaPMPDatabaseFinished( 115 void SafePicasaAlbumTableReader::OnParsePicasaPMPDatabaseFinished(
97 bool parse_success, 116 bool parse_success,
98 const std::vector<AlbumInfo>& albums, 117 const std::vector<AlbumInfo>& albums,
99 const std::vector<AlbumInfo>& folders) { 118 const std::vector<AlbumInfo>& folders) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
120 DCHECK(!callback_.is_null());
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, base::Bind(callback_, parse_success, albums, folders));
106 base::Bind(callback_, parse_success, albums, folders));
107 parser_state_ = FINISHED_PARSING_STATE; 126 parser_state_ = FINISHED_PARSING_STATE;
108 } 127 }
109 128
110 void SafePicasaAlbumTableReader::OnProcessCrashed(int exit_code) { 129 void SafePicasaAlbumTableReader::OnProcessCrashed(int exit_code) {
111 OnParsePicasaPMPDatabaseFinished(false, std::vector<AlbumInfo>(), 130 DLOG(ERROR) << "SafePicasaAlbumTableReader::OnProcessCrashed()";
112 std::vector<AlbumInfo>()); 131 OnParsePicasaPMPDatabaseFinished(
132 false, std::vector<AlbumInfo>(), std::vector<AlbumInfo>());
113 } 133 }
114 134
115 bool SafePicasaAlbumTableReader::OnMessageReceived( 135 bool SafePicasaAlbumTableReader::OnMessageReceived(
116 const IPC::Message& message) { 136 const IPC::Message& message) {
117 bool handled = true; 137 bool handled = true;
118 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumTableReader, message) 138 IPC_BEGIN_MESSAGE_MAP(SafePicasaAlbumTableReader, message)
119 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted, 139 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ProcessStarted,
120 OnProcessStarted) 140 OnProcessStarted)
121 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished, 141 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_ParsePicasaPMPDatabase_Finished,
122 OnParsePicasaPMPDatabaseFinished) 142 OnParsePicasaPMPDatabaseFinished)
123 IPC_MESSAGE_UNHANDLED(handled = false) 143 IPC_MESSAGE_UNHANDLED(handled = false)
124 IPC_END_MESSAGE_MAP() 144 IPC_END_MESSAGE_MAP()
125 return handled; 145 return handled;
126 } 146 }
127 147
128 } // namespace picasa 148 } // namespace picasa
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698