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

Side by Side Diff: chrome/browser/media_galleries/fileapi/safe_media_metadata_parser.h

Issue 1550593002: Switch to standard integer types in chrome/browser/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
7 7
8 #include <stdint.h>
9
8 #include <string> 10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/callback.h" 13 #include "base/callback.h"
12 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
15 #include "chrome/common/extensions/api/media_galleries.h" 18 #include "chrome/common/extensions/api/media_galleries.h"
16 #include "chrome/common/media_galleries/metadata_types.h" 19 #include "chrome/common/media_galleries/metadata_types.h"
17 #include "content/public/browser/utility_process_host.h" 20 #include "content/public/browser/utility_process_host.h"
18 #include "content/public/browser/utility_process_host_client.h" 21 #include "content/public/browser/utility_process_host_client.h"
19 22
20 namespace IPC { 23 namespace IPC {
21 class Message; 24 class Message;
22 } 25 }
23 26
24 class Profile; 27 class Profile;
25 28
26 namespace metadata { 29 namespace metadata {
27 30
28 // Parses the media metadata of a Blob safely in a utility process. This class 31 // Parses the media metadata of a Blob safely in a utility process. This class
29 // expects the MIME type of the Blob to be already determined. It spawns a 32 // expects the MIME type of the Blob to be already determined. It spawns a
30 // utility process to do further MIME-type specific metadata extraction. 33 // utility process to do further MIME-type specific metadata extraction.
31 // All public methods and callbacks of this class run on the UI thread. 34 // All public methods and callbacks of this class run on the UI thread.
32 class SafeMediaMetadataParser : public content::UtilityProcessHostClient { 35 class SafeMediaMetadataParser : public content::UtilityProcessHostClient {
33 public: 36 public:
34 // |metadata_dictionary| is owned by the callback. 37 // |metadata_dictionary| is owned by the callback.
35 typedef base::Callback< 38 typedef base::Callback<
36 void(bool parse_success, 39 void(bool parse_success,
37 scoped_ptr<base::DictionaryValue> metadata_dictionary, 40 scoped_ptr<base::DictionaryValue> metadata_dictionary,
38 scoped_ptr<std::vector<AttachedImage> > attached_images)> 41 scoped_ptr<std::vector<AttachedImage> > attached_images)>
39 DoneCallback; 42 DoneCallback;
40 43
41 SafeMediaMetadataParser(Profile* profile, const std::string& blob_uuid, 44 SafeMediaMetadataParser(Profile* profile,
42 int64 blob_size, const std::string& mime_type, 45 const std::string& blob_uuid,
46 int64_t blob_size,
47 const std::string& mime_type,
43 bool get_attached_images); 48 bool get_attached_images);
44 49
45 // Should be called on the UI thread. |callback| also runs on the UI thread. 50 // Should be called on the UI thread. |callback| also runs on the UI thread.
46 void Start(const DoneCallback& callback); 51 void Start(const DoneCallback& callback);
47 52
48 private: 53 private:
49 enum ParserState { 54 enum ParserState {
50 INITIAL_STATE, 55 INITIAL_STATE,
51 STARTED_PARSING_STATE, 56 STARTED_PARSING_STATE,
52 FINISHED_PARSING_STATE, 57 FINISHED_PARSING_STATE,
53 }; 58 };
54 59
55 // Private because content::UtilityProcessHostClient is ref-counted. 60 // Private because content::UtilityProcessHostClient is ref-counted.
56 ~SafeMediaMetadataParser() override; 61 ~SafeMediaMetadataParser() override;
57 62
58 // Launches the utility process. Must run on the IO thread. 63 // Launches the utility process. Must run on the IO thread.
59 void StartWorkOnIOThread(const DoneCallback& callback); 64 void StartWorkOnIOThread(const DoneCallback& callback);
60 65
61 // Notification from the utility process when it finishes parsing metadata. 66 // Notification from the utility process when it finishes parsing metadata.
62 // Runs on the IO thread. 67 // Runs on the IO thread.
63 void OnParseMediaMetadataFinished( 68 void OnParseMediaMetadataFinished(
64 bool parse_success, const base::DictionaryValue& metadata_dictionary, 69 bool parse_success, const base::DictionaryValue& metadata_dictionary,
65 const std::vector<AttachedImage>& attached_images); 70 const std::vector<AttachedImage>& attached_images);
66 71
67 // Sequence of functions that bounces from the IO thread to the UI thread to 72 // Sequence of functions that bounces from the IO thread to the UI thread to
68 // read the blob data, then sends the data back to the utility process. 73 // read the blob data, then sends the data back to the utility process.
69 void OnUtilityProcessRequestBlobBytes(int64 request_id, int64 byte_start, 74 void OnUtilityProcessRequestBlobBytes(int64_t request_id,
70 int64 length); 75 int64_t byte_start,
71 void StartBlobReaderOnUIThread(int64 request_id, int64 byte_start, 76 int64_t length);
72 int64 length); 77 void StartBlobReaderOnUIThread(int64_t request_id,
73 void OnBlobReaderDoneOnUIThread(int64 request_id, 78 int64_t byte_start,
79 int64_t length);
80 void OnBlobReaderDoneOnUIThread(int64_t request_id,
74 scoped_ptr<std::string> data, 81 scoped_ptr<std::string> data,
75 int64 /* blob_total_size */); 82 int64_t /* blob_total_size */);
76 void FinishRequestBlobBytes(int64 request_id, scoped_ptr<std::string> data); 83 void FinishRequestBlobBytes(int64_t request_id, scoped_ptr<std::string> data);
77 84
78 // UtilityProcessHostClient implementation. 85 // UtilityProcessHostClient implementation.
79 // Runs on the IO thread. 86 // Runs on the IO thread.
80 void OnProcessCrashed(int exit_code) override; 87 void OnProcessCrashed(int exit_code) override;
81 bool OnMessageReceived(const IPC::Message& message) override; 88 bool OnMessageReceived(const IPC::Message& message) override;
82 89
83 // All member variables are only accessed on the IO thread. 90 // All member variables are only accessed on the IO thread.
84 Profile* const profile_; 91 Profile* const profile_;
85 const std::string blob_uuid_; 92 const std::string blob_uuid_;
86 const int64 blob_size_; 93 const int64_t blob_size_;
87 const std::string mime_type_; 94 const std::string mime_type_;
88 bool get_attached_images_; 95 bool get_attached_images_;
89 96
90 DoneCallback callback_; 97 DoneCallback callback_;
91 98
92 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; 99 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
93 100
94 // Verifies the messages from the utility process came at the right time. 101 // Verifies the messages from the utility process came at the right time.
95 // Initialized on the UI thread, but only accessed on the IO thread. 102 // Initialized on the UI thread, but only accessed on the IO thread.
96 ParserState parser_state_; 103 ParserState parser_state_;
97 104
98 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser); 105 DISALLOW_COPY_AND_ASSIGN(SafeMediaMetadataParser);
99 }; 106 };
100 107
101 } // namespace metadata 108 } // namespace metadata
102 109
103 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_ 110 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698