1 // Copyright 2018 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.
4 
5 #ifndef CHROME_CHROME_CLEANER_UI_MAIN_DIALOG_API_H_
6 #define CHROME_CHROME_CLEANER_UI_MAIN_DIALOG_API_H_
7 
8 #include <windows.h>
9 
10 #include <string>
11 #include <vector>
12 
13 #include "base/callback.h"
14 #include "chrome/chrome_cleaner/constants/uws_id.h"
15 #include "chrome/chrome_cleaner/os/digest_verifier.h"
16 #include "chrome/chrome_cleaner/os/file_path_set.h"
17 #include "components/chrome_cleaner/public/constants/result_codes.h"
18 
19 namespace chrome_cleaner {
20 
21 // A set of callbacks for either the main controller or test code.
22 class MainDialogDelegate {
23  public:
24   virtual ~MainDialogDelegate() = default;
25 
26   // Identifies whether the user accepted the cleanup (|confirmed| is true).
27   virtual void AcceptedCleanup(bool confirmed) = 0;
28 
29   // Called when the main dialog is closed.
30   virtual void OnClose() = 0;
31 };
32 
33 // An abstract base class to be used as an API for the MainDialog, which can
34 // be replaced for testing purposes.
35 class MainDialogAPI {
36  public:
MainDialogAPI(MainDialogDelegate * delegate)37   explicit MainDialogAPI(MainDialogDelegate* delegate) : delegate_(delegate) {}
~MainDialogAPI()38   virtual ~MainDialogAPI() {}
39 
40   // Create the dialog. This must be called before any of the other methods.
41   virtual bool Create() = 0;
42 
43   // Show the "No PUPs found" message.
44   virtual void NoPUPsFound() = 0;
45 
46   // Set the dialog to the "done cleanup" state. The message to be displayed
47   // depends on the value of |cleanup_result|.
48   virtual void CleanupDone(ResultCode cleanup_result) = 0;
49 
50   // Close the window.
51   virtual void Close() = 0;
52 
53   // Disables |extensions| by telling Chrome to do so.
54   // Calls the |on_disable| with the result on completion.
55   virtual void DisableExtensions(const std::vector<std::wstring>& extensions,
56                                  base::OnceCallback<void(bool)> on_disable) = 0;
57 
58   // Checks if |found_pups| contains any files to clean. If so, calls
59   // ConfirmCleanupWithFiles, otherwise calls NoPUPsFound.
60   void ConfirmCleanupIfNeeded(const std::vector<UwSId>& found_pups,
61                               scoped_refptr<DigestVerifier> digest_verifier);
62 
63  protected:
64   // Ask the user to confirm the cleanup of the PUPs in |found_pups|, which
65   // will involve removing the files in |files_to_remove| and cleaning registry
66   // keys in |registry_keys|. This is only the list of items reported to the
67   // user; it doesn't affect the items that will actually be cleaned.
68   virtual void ConfirmCleanup(
69       const std::vector<UwSId>& found_pups,
70       const FilePathSet& files_to_remove,
71       const std::vector<std::wstring>& registry_keys) = 0;
72 
delegate()73   MainDialogDelegate* delegate() { return delegate_; }
74 
75  private:
76   MainDialogDelegate* delegate_;  // Weak.
77 };
78 
79 }  // namespace chrome_cleaner
80 
81 #endif  // CHROME_CHROME_CLEANER_UI_MAIN_DIALOG_API_H_
82