summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/fake_safe_browsing_database_manager.h
blob: 2a91b73f9638dc1dd7b86069df56252fa3eb2330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_
#define CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_

#include <set>
#include <string>

#include "chrome/browser/safe_browsing/database_manager.h"

namespace extensions {

// A fake safe browsing database manager for use with extensions tests.
//
// By default it is disabled (returning true and ignoring |unsafe_ids_|);
// call set_enabled to enable it.
class FakeSafeBrowsingDatabaseManager : public SafeBrowsingDatabaseManager {
 public:
  FakeSafeBrowsingDatabaseManager();

  // Returns true if synchronously safe, false if not in which case the unsafe
  // IDs taken from |unsafe_ids_| are passed to to |client| on the current
  // message loop.
  virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids,
                                 Client* client) OVERRIDE;

  void set_enabled(bool enabled) { enabled_ = enabled; }

  void set_unsafe_ids(const std::set<std::string>& unsafe_ids) {
    unsafe_ids_ = unsafe_ids;
  }

 private:
  virtual ~FakeSafeBrowsingDatabaseManager();

  // Runs client->SafeBrowsingResult(result).
  void OnSafeBrowsingResult(scoped_ptr<SafeBrowsingCheck> result,
                            Client* client);

  // Whether to respond to CheckExtensionIDs immediately with true (indicating
  // that there is definitely no extension ID match).
  bool enabled_;

  // The extension IDs considered unsafe.
  std::set<std::string> unsafe_ids_;
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_FAKE_SAFE_BROWSING_DATABASE_MANAGER_H_