| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_TEST_BASE_MOJO_TEST_CONNECTOR_H_ | 5 #ifndef CHROME_INSTALLER_SETUP_PERSISTENT_HISTOGRAM_STORAGE_H_ |
| 6 #define CHROME_TEST_BASE_MOJO_TEST_CONNECTOR_H_ | 6 #define CHROME_INSTALLER_SETUP_PERSISTENT_HISTOGRAM_STORAGE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 namespace installer { |
| 11 #include "base/process/process_handle.h" | |
| 12 #include "base/test/launcher/test_launcher.h" | |
| 13 #include "services/shell/background/background_shell.h" | |
| 14 #include "services/shell/public/interfaces/service.mojom.h" | |
| 15 | 12 |
| 16 namespace base { | 13 // When a PersistentHistogramStorage is destructed, histograms recorded during |
| 17 class CommandLine; | 14 // its lifetime are persisted in the directory set by set_storage_dir(). |
| 18 } | 15 // Histograms are not persisted if set_storage_dir() has not been called or if |
| 16 // the storage directory does not exist on destruction. |
| 17 // PersistentHistogramStorage should be instantiated as early as possible in the |
| 18 // process lifetime and should never be instantiated again. Persisted histograms |
| 19 // will eventually be reported by the browser process. |
| 20 class PersistentHistogramStorage { |
| 21 public: |
| 22 PersistentHistogramStorage(); |
| 23 ~PersistentHistogramStorage(); |
| 19 | 24 |
| 20 namespace content { | 25 // Sets |storage_dir| as the directory in which histograms will be persisted |
| 21 class TestState; | 26 // when this PersistentHistogramStorage is destructed. |
| 22 } | 27 void set_storage_dir(const base::FilePath& storage_dir) { |
| 28 storage_dir_ = storage_dir; |
| 29 } |
| 23 | 30 |
| 24 // MojoTestConnector in responsible for providing the necessary wiring for | 31 // Returns a directory in which setup histograms must be persisted to be |
| 25 // test processes to get a mojo channel passed to them. To use this class | 32 // reported by a product installed in |target_path|. Should be used as |
| 26 // call PrepareForTest() prior to launching each test. It is expected | 33 // argument to set_storage_dir(). |
| 27 // PrepareForTest() is called from content::TestLauncherDelegate::PreRunTest(). | 34 static base::FilePath GetReportedStorageDir( |
| 28 class MojoTestConnector { | 35 const base::FilePath& target_path); |
| 29 public: | |
| 30 // Switch added to command line of each test. | |
| 31 static const char kTestSwitch[]; | |
| 32 | |
| 33 // Command line switch added to all apps that are expected to be provided by | |
| 34 // browser_tests. | |
| 35 static const char kMashApp[]; | |
| 36 | |
| 37 MojoTestConnector(); | |
| 38 ~MojoTestConnector(); | |
| 39 | |
| 40 // Initializes the background thread the Shell runs on. | |
| 41 shell::mojom::ServiceRequest Init(); | |
| 42 | |
| 43 std::unique_ptr<content::TestState> PrepareForTest( | |
| 44 base::CommandLine* command_line, | |
| 45 base::TestLauncher::LaunchOptions* test_launch_options); | |
| 46 | 36 |
| 47 private: | 37 private: |
| 48 class NativeRunnerDelegateImpl; | 38 base::FilePath storage_dir_; |
| 49 | 39 |
| 50 std::unique_ptr<NativeRunnerDelegateImpl> native_runner_delegate_; | 40 DISALLOW_COPY_AND_ASSIGN(PersistentHistogramStorage); |
| 51 | |
| 52 shell::BackgroundShell background_shell_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(MojoTestConnector); | |
| 55 }; | 41 }; |
| 56 | 42 |
| 57 #endif // CHROME_TEST_BASE_MOJO_TEST_CONNECTOR_H_ | 43 } // namespace installer |
| 44 |
| 45 #endif // CHROME_INSTALLER_SETUP_PERSISTENT_HISTOGRAM_STORAGE_H_ |
| OLD | NEW |