base::Time multiplicative operator overloading
[chromium-blink-merge.git] / chrome / browser / extensions / blacklist_state_fetcher.h
blobb95e322e61356a65ce9dafb7bc6afc9397a87f18
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_BLACKLIST_STATE_FETCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_BLACKLIST_STATE_FETCHER_H_
8 #include <set>
9 #include <string>
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/safe_browsing/protocol_manager_helper.h"
15 #include "extensions/browser/blacklist_state.h"
16 #include "net/url_request/url_fetcher.h"
17 #include "net/url_request/url_fetcher_delegate.h"
19 namespace net {
20 class URLRequestContextGetter;
23 namespace extensions {
25 class BlacklistStateFetcher : public net::URLFetcherDelegate {
26 public:
27 typedef base::Callback<void(BlacklistState)> RequestCallback;
29 BlacklistStateFetcher();
31 ~BlacklistStateFetcher() override;
33 virtual void Request(const std::string& id, const RequestCallback& callback);
35 void SetSafeBrowsingConfig(const SafeBrowsingProtocolConfig& config);
37 void SetURLRequestContextForTest(
38 net::URLRequestContextGetter* parent_request_context);
40 protected:
41 // net::URLFetcherDelegate interface.
42 void OnURLFetchComplete(const net::URLFetcher* source) override;
44 private:
45 typedef std::multimap<std::string, RequestCallback> CallbackMultiMap;
47 GURL RequestUrl() const;
49 void SaveRequestContext(
50 const std::string& id,
51 scoped_refptr<net::URLRequestContextGetter> request_context_getter);
53 void SendRequest(const std::string& id);
55 // ID for URLFetchers for testing.
56 int url_fetcher_id_;
58 scoped_ptr<SafeBrowsingProtocolConfig> safe_browsing_config_;
59 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
60 scoped_refptr<net::URLRequestContextGetter> parent_request_context_for_test_;
62 // Extension id by URLFetcher.
63 std::map<const net::URLFetcher*, std::string> requests_;
65 // Callbacks by extension ID.
66 CallbackMultiMap callbacks_;
68 base::WeakPtrFactory<BlacklistStateFetcher> weak_ptr_factory_;
70 DISALLOW_COPY_AND_ASSIGN(BlacklistStateFetcher);
73 } // namespace extensions
75 #endif // CHROME_BROWSER_EXTENSIONS_BLACKLIST_STATE_FETCHER_H_