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

Side by Side Diff: chrome/browser/extensions/api/feedback_private/feedback_private_api.h

Issue 2840103002: Add new API function: feedbackPrivate.readLogSource (Closed)
Patch Set: Addressed comments from Patch Set 4 Created 3 years, 7 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H_
7 7
8 #include "chrome/browser/extensions/chrome_extension_function.h" 8 #include "chrome/browser/extensions/chrome_extension_function.h"
9 #include "chrome/browser/feedback/system_logs/system_logs_fetcher_base.h" 9 #include "chrome/browser/feedback/system_logs/system_logs_fetcher_base.h"
10 #include "chrome/common/extensions/api/feedback_private.h" 10 #include "chrome/common/extensions/api/feedback_private.h"
11 #include "extensions/browser/browser_context_keyed_api_factory.h" 11 #include "extensions/browser/browser_context_keyed_api_factory.h"
12 #include "extensions/browser/extension_function.h" 12 #include "extensions/browser/extension_function.h"
13 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
14 14
15 #if defined(OS_CHROMEOS)
16 #include "base/time/time.h"
17 #include "chrome/browser/extensions/api/feedback_private/log_source_access_manag er.h"
18 #include "chrome/browser/extensions/api/feedback_private/log_source_resource.h"
19 #endif // defined(OS_CHROMEOS)
20
15 namespace extensions { 21 namespace extensions {
16 22
17 class FeedbackService; 23 class FeedbackService;
18 24
19 class FeedbackPrivateAPI : public BrowserContextKeyedAPI { 25 class FeedbackPrivateAPI : public BrowserContextKeyedAPI {
20 public: 26 public:
21 explicit FeedbackPrivateAPI(content::BrowserContext* context); 27 explicit FeedbackPrivateAPI(content::BrowserContext* context);
22 ~FeedbackPrivateAPI() override; 28 ~FeedbackPrivateAPI() override;
23 29
24 FeedbackService* GetService() const; 30 FeedbackService* GetService() const;
25 31
32 #if defined(OS_CHROMEOS)
33 LogSourceAccessManager* GetLogSourceAccessManager() {
tbarzic 2017/05/25 22:46:45 for simple getters/setters this would be preferred
Simon Que 2017/05/26 04:34:38 Done.
34 return access_manager_;
35 }
36 #endif // defined(OS_CHROMEOS)
37
26 void RequestFeedback(const std::string& description_template, 38 void RequestFeedback(const std::string& description_template,
27 const std::string& category_tag, 39 const std::string& category_tag,
28 const GURL& page_url); 40 const GURL& page_url);
29 41
30 void RequestFeedbackForFlow(const std::string& description_template, 42 void RequestFeedbackForFlow(const std::string& description_template,
31 const std::string& category_tag, 43 const std::string& category_tag,
32 const GURL& page_url, 44 const GURL& page_url,
33 api::feedback_private::FeedbackFlow flow); 45 api::feedback_private::FeedbackFlow flow);
34 46
35 // BrowserContextKeyedAPI implementation. 47 // BrowserContextKeyedAPI implementation.
36 static BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>* 48 static BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>*
37 GetFactoryInstance(); 49 GetFactoryInstance();
38 50
39 private: 51 private:
40 friend class BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>; 52 friend class BrowserContextKeyedAPIFactory<FeedbackPrivateAPI>;
41 53
42 // BrowserContextKeyedAPI implementation. 54 // BrowserContextKeyedAPI implementation.
43 static const char* service_name() { 55 static const char* service_name() {
44 return "FeedbackPrivateAPI"; 56 return "FeedbackPrivateAPI";
45 } 57 }
46 58
47 static const bool kServiceHasOwnInstanceInIncognito = true; 59 static const bool kServiceHasOwnInstanceInIncognito = true;
48 60
49 content::BrowserContext* const browser_context_; 61 content::BrowserContext* const browser_context_;
50 FeedbackService* service_; 62 FeedbackService* service_;
63
64 #if defined(OS_CHROMEOS)
65 LogSourceAccessManager* access_manager_;
66 #endif // defined(OS_CHROMEOS)
51 }; 67 };
52 68
53 // Feedback strings. 69 // Feedback strings.
54 class FeedbackPrivateGetStringsFunction : public UIThreadExtensionFunction { 70 class FeedbackPrivateGetStringsFunction : public UIThreadExtensionFunction {
55 public: 71 public:
56 DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getStrings", 72 DECLARE_EXTENSION_FUNCTION("feedbackPrivate.getStrings",
57 FEEDBACKPRIVATE_GETSTRINGS) 73 FEEDBACKPRIVATE_GETSTRINGS)
58 74
59 // Invoke this callback when this function is called - used for testing. 75 // Invoke this callback when this function is called - used for testing.
60 static void set_test_callback(base::Closure* const callback) { 76 static void set_test_callback(base::Closure* const callback) {
(...skipping 27 matching lines...) Expand all
88 FEEDBACKPRIVATE_GETSYSTEMINFORMATION); 104 FEEDBACKPRIVATE_GETSYSTEMINFORMATION);
89 105
90 protected: 106 protected:
91 ~FeedbackPrivateGetSystemInformationFunction() override {} 107 ~FeedbackPrivateGetSystemInformationFunction() override {}
92 ResponseAction Run() override; 108 ResponseAction Run() override;
93 109
94 private: 110 private:
95 void OnCompleted(std::unique_ptr<system_logs::SystemLogsResponse> sys_info); 111 void OnCompleted(std::unique_ptr<system_logs::SystemLogsResponse> sys_info);
96 }; 112 };
97 113
114 // This function only reads from actual log sources on Chrome OS. On other
115 // platforms, it just returns EmptyResponse().
116 class FeedbackPrivateReadLogSourceFunction : public UIThreadExtensionFunction {
117 public:
118 DECLARE_EXTENSION_FUNCTION("feedbackPrivate.readLogSource",
119 FEEDBACKPRIVATE_READLOGSOURCE);
120
121 #if defined(OS_CHROMEOS)
122 // To override the default rate-limiting mechanism of this function, pass in
123 // a TimeDelta representing the desired minimum time between consecutive reads
124 // of a source from an extension. Does not take ownership of |timeout|. When
125 // done testing, call this function again with |timeout|=nullptr to reset to
126 // the default behavior.
127 static void SetRateLimitingTimeoutForTesting(const base::TimeDelta* timeout);
128 #endif // defined(OS_CHROMEOS)
129
130 protected:
131 ~FeedbackPrivateReadLogSourceFunction() override {}
132 ResponseAction Run() override;
133
134 #if defined(OS_CHROMEOS)
135 private:
136 // Looks for an existing LogSourceResource in the API Resource Manager with
137 // id=|reader_id|.
138 // - If the resource exists and was created by the same extension, returns the
139 // resource.
140 // - If the resource exists and was created by a different extension, returns
141 // nullptr.
142 // - If the resource does not exist and there is no existing resource with
143 // source=|source| for the current extension, creates one, stores it in the
144 // API Resource Manager, and returns it.
145 // - If the resource does not exist and there is already an existing resource
146 // source=|source| for the current extension, returns nullptr.
147 //
148 // All returned pointers are owned by the API Resource Manager.
149 LogSourceResource* GetOrCreateLogSourceResource(
150 int reader_id,
151 api::feedback_private::LogSource source);
152
153 void OnCompleted(api::feedback_private::LogSource source,
154 int readerId,
155 bool incremental,
156 system_logs::SystemLogsResponse* response);
157 #endif // defined(OS_CHROMEOS)
158 };
159
98 class FeedbackPrivateSendFeedbackFunction 160 class FeedbackPrivateSendFeedbackFunction
99 : public ChromeAsyncExtensionFunction { 161 : public ChromeAsyncExtensionFunction {
100 public: 162 public:
101 DECLARE_EXTENSION_FUNCTION("feedbackPrivate.sendFeedback", 163 DECLARE_EXTENSION_FUNCTION("feedbackPrivate.sendFeedback",
102 FEEDBACKPRIVATE_SENDFEEDBACK); 164 FEEDBACKPRIVATE_SENDFEEDBACK);
103 165
104 protected: 166 protected:
105 ~FeedbackPrivateSendFeedbackFunction() override {} 167 ~FeedbackPrivateSendFeedbackFunction() override {}
106 bool RunAsync() override; 168 bool RunAsync() override;
107 169
108 private: 170 private:
109 void OnCompleted(bool success); 171 void OnCompleted(bool success);
110 }; 172 };
111 173
112 class FeedbackPrivateLogSrtPromptResultFunction 174 class FeedbackPrivateLogSrtPromptResultFunction
113 : public UIThreadExtensionFunction { 175 : public UIThreadExtensionFunction {
114 public: 176 public:
115 DECLARE_EXTENSION_FUNCTION("feedbackPrivate.logSrtPromptResult", 177 DECLARE_EXTENSION_FUNCTION("feedbackPrivate.logSrtPromptResult",
116 FEEDBACKPRIVATE_LOGSRTPROMPTRESULT); 178 FEEDBACKPRIVATE_LOGSRTPROMPTRESULT);
117 179
118 protected: 180 protected:
119 ~FeedbackPrivateLogSrtPromptResultFunction() override {} 181 ~FeedbackPrivateLogSrtPromptResultFunction() override {}
120 AsyncExtensionFunction::ResponseAction Run() override; 182 AsyncExtensionFunction::ResponseAction Run() override;
121 }; 183 };
122 184
123 } // namespace extensions 185 } // namespace extensions
124 186
125 #endif // CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H _ 187 #endif // CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_PRIVATE_API_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698