summaryrefslogtreecommitdiffstats
path: root/chrome/browser/android/ntp/ntp_snippets_launcher.h
blob: 0d509dec3e9a64aea291b6631df0db318ed78eda (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
// Copyright 2016 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_ANDROID_NTP_NTP_SNIPPETS_LAUNCHER_H_
#define CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_LAUNCHER_H_

#include "base/android/jni_android.h"
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "components/ntp_snippets/ntp_snippets_scheduler.h"

// Android implementation of ntp_snippets::NTPSnippetsScheduler.
// The NTPSnippetsLauncher singleton owns the Java SnippetsLauncher object, and
// is used to schedule the fetching of snippets. Runs on the UI thread.
class NTPSnippetsLauncher : public ntp_snippets::NTPSnippetsScheduler {
 public:
  static NTPSnippetsLauncher* Get();

  static bool Register(JNIEnv* env);

  // ntp_snippets::NTPSnippetsScheduler implementation.
  bool Schedule(base::TimeDelta period_wifi_charging,
                base::TimeDelta period_wifi,
                base::TimeDelta period_fallback) override;
  bool Unschedule() override;

 private:
  friend struct base::DefaultLazyInstanceTraits<NTPSnippetsLauncher>;

  // Constructor and destructor marked private to enforce singleton.
  NTPSnippetsLauncher();
  virtual ~NTPSnippetsLauncher();

  base::android::ScopedJavaGlobalRef<jobject> java_launcher_;

  DISALLOW_COPY_AND_ASSIGN(NTPSnippetsLauncher);
};

#endif  // CHROME_BROWSER_ANDROID_NTP_NTP_SNIPPETS_LAUNCHER_H_