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 #ifndef CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_ | 5 #ifndef CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_ |
6 #define CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_ | 6 #define CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // //do something with the logs | 53 // //do something with the logs |
54 // } | 54 // } |
55 // void GetLogs() { | 55 // void GetLogs() { |
56 // SystemLogsFetcherBase* fetcher = new SystemLogsFetcherBase(); | 56 // SystemLogsFetcherBase* fetcher = new SystemLogsFetcherBase(); |
57 // fetcher->Fetch(base::Bind(&Example::ProcessLogs, this)); | 57 // fetcher->Fetch(base::Bind(&Example::ProcessLogs, this)); |
58 // } | 58 // } |
59 class SystemLogsFetcherBase | 59 class SystemLogsFetcherBase |
60 : public base::SupportsWeakPtr<SystemLogsFetcherBase> { | 60 : public base::SupportsWeakPtr<SystemLogsFetcherBase> { |
61 public: | 61 public: |
62 SystemLogsFetcherBase(); | 62 SystemLogsFetcherBase(); |
63 ~SystemLogsFetcherBase(); | 63 virtual ~SystemLogsFetcherBase(); |
64 | 64 |
65 void Fetch(const SysLogsFetcherCallback& callback); | 65 void Fetch(const SysLogsFetcherCallback& callback); |
66 | 66 |
67 protected: | 67 protected: |
68 // Callback passed to all the data sources. It merges the |data| it receives | 68 // Callback passed to all the data sources. Calls Rewrite() and AddResponse(). |
69 // into response_. When all the data sources have responded, it deletes their | 69 void OnFetched(const std::string& source_name, SystemLogsResponse* response); |
70 // objects and returns the response to the callback_. After this it | 70 |
71 // deletes this instance of the object. | 71 // Virtual function that allows derived classes to modify the response before |
| 72 // it gets added to the output. |
| 73 virtual void Rewrite(const std::string& source_name, |
| 74 SystemLogsResponse* response); |
| 75 |
| 76 // Merges the |data| it receives into response_. When all the data sources |
| 77 // have responded, it deletes their objects and returns the response to the |
| 78 // callback_. After this it deletes this instance of the object. |
72 void AddResponse(const std::string& source_name, | 79 void AddResponse(const std::string& source_name, |
73 SystemLogsResponse* response); | 80 SystemLogsResponse* response); |
74 | 81 |
75 ScopedVector<SystemLogsSource> data_sources_; | 82 ScopedVector<SystemLogsSource> data_sources_; |
76 SysLogsFetcherCallback callback_; | 83 SysLogsFetcherCallback callback_; |
77 | 84 |
78 scoped_ptr<SystemLogsResponse> response_; // The actual response data. | 85 scoped_ptr<SystemLogsResponse> response_; // The actual response data. |
79 size_t num_pending_requests_; // The number of callbacks it should get. | 86 size_t num_pending_requests_; // The number of callbacks it should get. |
80 | 87 |
81 private: | 88 private: |
82 | 89 |
83 DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcherBase); | 90 DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcherBase); |
84 }; | 91 }; |
85 | 92 |
86 } // namespace system_logs | 93 } // namespace system_logs |
87 | 94 |
88 #endif // CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_ | 95 #endif // CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_ |
OLD | NEW |