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

Side by Side Diff: content/browser/download/mhtml_generation_manager.h

Issue 2683493002: Get signals working in the EXTRA_DATA section of MHTML (Closed)
Patch Set: Dimich CR fixes Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ 4 #ifndef CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
5 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ 5 #define CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/files/file.h" 14 #include "base/files/file.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/process/process.h" 17 #include "base/process/process.h"
18 #include "base/supports_user_data.h"
18 #include "content/common/download/mhtml_save_status.h" 19 #include "content/common/download/mhtml_save_status.h"
20 #include "content/public/browser/web_contents.h"
19 #include "content/public/common/mhtml_generation_params.h" 21 #include "content/public/common/mhtml_generation_params.h"
20 #include "ipc/ipc_platform_file.h" 22 #include "ipc/ipc_platform_file.h"
21 23
22 namespace base { 24 namespace base {
23 class FilePath; 25 class FilePath;
24 } 26 }
25 27
26 namespace content { 28 namespace content {
27 29
28 class RenderFrameHostImpl; 30 class RenderFrameHostImpl;
29 class WebContents; 31 class WebContents;
30 32
31 // The class and all of its members live on the UI thread. Only static methods 33 // The class and all of its members live on the UI thread. Only static methods
32 // are executed on other threads. 34 // are executed on other threads.
33 // 35 //
34 // MHTMLGenerationManager is a singleton. Each call to SaveMHTML method creates 36 // MHTMLGenerationManager is a singleton. Each call to SaveMHTML method creates
35 // a new instance of MHTMLGenerationManager::Job that tracks generation of a 37 // a new instance of MHTMLGenerationManager::Job that tracks generation of a
36 // single MHTML file. 38 // single MHTML file.
37 class MHTMLGenerationManager { 39 class CONTENT_EXPORT MHTMLGenerationManager {
38 public: 40 public:
39 static MHTMLGenerationManager* GetInstance(); 41 static MHTMLGenerationManager* GetInstance();
40 42
41 // GenerateMHTMLCallback is called to report completion and status of MHTML 43 // GenerateMHTMLCallback is called to report completion and status of MHTML
42 // generation. On success |file_size| indicates the size of the 44 // generation. On success |file_size| indicates the size of the
43 // generated file. On failure |file_size| is -1. 45 // generated file. On failure |file_size| is -1.
44 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback; 46 typedef base::Callback<void(int64_t file_size)> GenerateMHTMLCallback;
45 47
46 // Instructs the RenderFrames in |web_contents| to generate a MHTML 48 // Instructs the RenderFrames in |web_contents| to generate a MHTML
47 // representation of the current page. 49 // representation of the current page.
48 void SaveMHTML(WebContents* web_contents, 50 void SaveMHTML(WebContents* web_contents,
49 const MHTMLGenerationParams& params, 51 const MHTMLGenerationParams& params,
50 const GenerateMHTMLCallback& callback); 52 const GenerateMHTMLCallback& callback);
51 53
52 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the 54 // Handler for FrameHostMsg_SerializeAsMHTMLResponse (a notification from the
53 // renderer that the MHTML generation finished for a single frame). 55 // renderer that the MHTML generation finished for a single frame).
54 void OnSerializeAsMHTMLResponse( 56 void OnSerializeAsMHTMLResponse(
55 RenderFrameHostImpl* sender, 57 RenderFrameHostImpl* sender,
56 int job_id, 58 int job_id,
57 MhtmlSaveStatus save_status, 59 MhtmlSaveStatus save_status,
58 const std::set<std::string>& digests_of_uris_of_serialized_resources, 60 const std::set<std::string>& digests_of_uris_of_serialized_resources,
59 base::TimeDelta renderer_main_thread_time); 61 base::TimeDelta renderer_main_thread_time);
60 62
63 // Contained class that represents an extra data part. With the addition of
64 // the MHTMLExtraData class, we can add enough information to create an extra
65 // MHTML part to be added into the complete file. For instance, this might
66 // be used for gathering load time signals in debug code for analysis, but
67 // the mechanism is fairly general, and could be used to add arbitrary parts.
68 // Specify the content type, content location, and body, and the methods in
69 // MHTMLExtraData will do the rest.
70 struct MHTMLExtraPart {
71 std::string content_type;
72 std::string content_location;
73 std::string body;
74 };
75
76 // Helper class to put extra parts into the WebContents user data, and take
77 // them back out again.
78 class MHTMLExtraData : public base::SupportsUserData::Data {
79 public:
80 MHTMLExtraData();
81 ~MHTMLExtraData() override;
82
83 // Get the data string out of the web contents. The web contents retains
84 // ownership of the vector. Returns nullptr if none found.
85 static std::vector<MHTMLExtraPart>* FromWebContents(
86 content::WebContents* contents);
87
88 // Add the extra part to the data structure stored by the WebContents.
89 static void AddPartToWebContents(content::WebContents* contents,
90 MHTMLExtraPart& part);
91
92 private:
93 std::vector<MHTMLExtraPart> parts_;
94 };
95
61 private: 96 private:
62 friend struct base::DefaultSingletonTraits<MHTMLGenerationManager>; 97 friend struct base::DefaultSingletonTraits<MHTMLGenerationManager>;
63 class Job; 98 class Job;
64 99
65 MHTMLGenerationManager(); 100 MHTMLGenerationManager();
66 virtual ~MHTMLGenerationManager(); 101 virtual ~MHTMLGenerationManager();
67 102
68 // Called on the file thread to create |file|. 103 // Called on the file thread to create |file|.
69 static base::File CreateFile(const base::FilePath& file_path); 104 static base::File CreateFile(const base::FilePath& file_path);
70 105
(...skipping 23 matching lines...) Expand all
94 std::map<int, std::unique_ptr<Job>> id_to_job_; 129 std::map<int, std::unique_ptr<Job>> id_to_job_;
95 130
96 int next_job_id_; 131 int next_job_id_;
97 132
98 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager); 133 DISALLOW_COPY_AND_ASSIGN(MHTMLGenerationManager);
99 }; 134 };
100 135
101 } // namespace content 136 } // namespace content
102 137
103 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_ 138 #endif // CONTENT_BROWSER_DOWNLOAD_MHTML_GENERATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698