Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_DOM_UI_CHROME_URL_DATA_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_ |
| 6 #define CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_ | 6 #define CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/singleton.h" | 12 #include "base/singleton.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 15 #include "chrome/browser/browser_thread.h" | |
| 15 | 16 |
| 16 class DictionaryValue; | 17 class DictionaryValue; |
| 17 class FilePath; | 18 class FilePath; |
| 18 class GURL; | 19 class GURL; |
| 19 class MessageLoop; | 20 class MessageLoop; |
| 20 class RefCountedMemory; | 21 class RefCountedMemory; |
| 21 class URLRequestChromeJob; | 22 class URLRequestChromeJob; |
| 22 | 23 |
| 23 namespace net { | 24 namespace net { |
| 24 class URLRequest; | 25 class URLRequest; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 35 public: | 36 public: |
| 36 // Returns the singleton instance. | 37 // Returns the singleton instance. |
| 37 static ChromeURLDataManager* GetInstance(); | 38 static ChromeURLDataManager* GetInstance(); |
| 38 | 39 |
| 39 typedef int RequestID; | 40 typedef int RequestID; |
| 40 | 41 |
| 41 // A DataSource is an object that can answer requests for data | 42 // A DataSource is an object that can answer requests for data |
| 42 // asynchronously. DataSources are collectively owned with refcounting smart | 43 // asynchronously. DataSources are collectively owned with refcounting smart |
| 43 // pointers and should never be deleted on the IO thread, since their calls | 44 // pointers and should never be deleted on the IO thread, since their calls |
| 44 // are handled almost always on the UI thread and there's a possibility of a | 45 // are handled almost always on the UI thread and there's a possibility of a |
| 45 // data race. | 46 // data race. The |DeleteOnUIThread| trait is used to enforce this. |
| 46 // | 47 // |
| 47 // An implementation of DataSource should handle calls to | 48 // An implementation of DataSource should handle calls to |
| 48 // StartDataRequest() by starting its (implementation-specific) asynchronous | 49 // StartDataRequest() by starting its (implementation-specific) asynchronous |
| 49 // request for the data, then call SendResponse() to notify | 50 // request for the data, then call SendResponse() to notify. |
| 50 class DataSource : public base::RefCountedThreadSafe<DataSource> { | 51 class DataSource : public base::RefCountedThreadSafe< |
| 52 DataSource, BrowserThread::DeleteOnUIThread> { | |
| 51 public: | 53 public: |
| 52 // See source_name_ and message_loop_ below for docs on these parameters. | 54 // See source_name_ and message_loop_ below for docs on these parameters. |
| 53 DataSource(const std::string& source_name, | 55 DataSource(const std::string& source_name, |
| 54 MessageLoop* message_loop); | 56 MessageLoop* message_loop); |
| 55 | 57 |
| 56 // Sent by the DataManager to request data at |path|. The source should | 58 // Sent by the DataManager to request data at |path|. The source should |
| 57 // call SendResponse() when the data is available or if the request could | 59 // call SendResponse() when the data is available or if the request could |
| 58 // not be satisfied. | 60 // not be satisfied. |
| 59 virtual void StartDataRequest(const std::string& path, | 61 virtual void StartDataRequest(const std::string& path, |
| 60 bool is_off_the_record, | 62 bool is_off_the_record, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 80 // contention. | 82 // contention. |
| 81 virtual MessageLoop* MessageLoopForRequestPath(const std::string& path) | 83 virtual MessageLoop* MessageLoopForRequestPath(const std::string& path) |
| 82 const; | 84 const; |
| 83 | 85 |
| 84 const std::string& source_name() const { return source_name_; } | 86 const std::string& source_name() const { return source_name_; } |
| 85 | 87 |
| 86 static void SetFontAndTextDirection(DictionaryValue* localized_strings); | 88 static void SetFontAndTextDirection(DictionaryValue* localized_strings); |
| 87 | 89 |
| 88 protected: | 90 protected: |
| 89 friend class base::RefCountedThreadSafe<DataSource>; | 91 friend class base::RefCountedThreadSafe<DataSource>; |
| 92 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | |
| 93 friend class DeleteTask<DataSource>; | |
| 90 | 94 |
| 91 virtual ~DataSource(); | 95 virtual ~DataSource(); |
| 92 | 96 |
| 93 private: | 97 private: |
| 94 // The name of this source. | 98 // The name of this source. |
| 95 // E.g., for favicons, this could be "favicon", which results in paths for | 99 // E.g., for favicons, this could be "favicon", which results in paths for |
| 96 // specific resources like "favicon/34" getting sent to this source. | 100 // specific resources like "favicon/34" getting sent to this source. |
| 97 const std::string source_name_; | 101 const std::string source_name_; |
| 98 | 102 |
| 99 // The MessageLoop for the thread where this DataSource lives. | 103 // The MessageLoop for the thread where this DataSource lives. |
| 100 // Used to send messages to the DataSource. | 104 // Used to send messages to the DataSource. |
| 101 MessageLoop* message_loop_; | 105 MessageLoop* message_loop_; |
| 102 }; | 106 }; |
|
eroman
2011/01/24 18:26:39
what happened to the indentation here? looks off.
ahendrickson
2011/01/24 19:58:20
Fixed. Didn't notice when Visual Studio reformatt
| |
| 103 | 107 |
| 104 // Add a DataSource to the collection of data sources. | 108 // Add a DataSource to the collection of data sources. |
| 105 // Because we don't track users of a given path, we can't know when it's | 109 // Because we don't track users of a given path, we can't know when it's |
| 106 // safe to remove them, so the added source effectively leaks. | 110 // safe to remove them, so the added source effectively leaks. |
| 107 // This could be improved in the future but currently the users of this | 111 // This could be improved in the future but currently the users of this |
| 108 // interface are conceptually permanent registration anyway. | 112 // interface are conceptually permanent registration anyway. |
| 109 // Adding a second DataSource with the same name clobbers the first. | 113 // Adding a second DataSource with the same name clobbers the first. |
| 110 // NOTE: Calling this from threads other the IO thread must be done via | 114 // NOTE: Calling this from threads other the IO thread must be done via |
| 111 // InvokeLater. | 115 // InvokeLater. |
| 112 void AddDataSource(scoped_refptr<DataSource> source); | 116 void AddDataSource(scoped_refptr<DataSource> source); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeURLDataManager); | 179 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeURLDataManager); |
| 176 | 180 |
| 177 // Register our special URL handler under our special URL scheme. | 181 // Register our special URL handler under our special URL scheme. |
| 178 // Must be done once at startup. | 182 // Must be done once at startup. |
| 179 void RegisterURLRequestChromeJob(); | 183 void RegisterURLRequestChromeJob(); |
| 180 | 184 |
| 181 // Undoes the registration done by RegisterURLRequestChromeJob. | 185 // Undoes the registration done by RegisterURLRequestChromeJob. |
| 182 void UnregisterURLRequestChromeJob(); | 186 void UnregisterURLRequestChromeJob(); |
| 183 | 187 |
| 184 #endif // CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_ | 188 #endif // CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_ |
| OLD | NEW |