| Index: components/offline_pages/background/save_page_request.cc
|
| diff --git a/components/offline_pages/background/save_page_request.cc b/components/offline_pages/background/save_page_request.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fdae22cfc451fda682cef1aa73dcfcfbd92cdee9
|
| --- /dev/null
|
| +++ b/components/offline_pages/background/save_page_request.cc
|
| @@ -0,0 +1,67 @@
|
| +// 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.
|
| +
|
| +#include "components/offline_pages/background/save_page_request.h"
|
| +
|
| +namespace offline_pages {
|
| +
|
| +SavePageRequest::SavePageRequest(int64_t request_id,
|
| + const GURL& url,
|
| + const ClientId& client_id,
|
| + const base::Time& creation_time)
|
| + : request_id_(request_id),
|
| + url_(url),
|
| + client_id_(client_id),
|
| + creation_time_(creation_time),
|
| + activation_time_(creation_time),
|
| + attempt_count_(0) {}
|
| +
|
| +SavePageRequest::SavePageRequest(int64_t request_id,
|
| + const GURL& url,
|
| + const ClientId& client_id,
|
| + const base::Time& creation_time,
|
| + const base::Time& activation_time)
|
| + : request_id_(request_id),
|
| + url_(url),
|
| + client_id_(client_id),
|
| + creation_time_(creation_time),
|
| + activation_time_(activation_time),
|
| + attempt_count_(0) {}
|
| +
|
| +SavePageRequest::~SavePageRequest() {}
|
| +
|
| +// TODO(fgorski): Introduce policy parameter, once policy is available.
|
| +SavePageRequest::Status SavePageRequest::GetStatus(
|
| + const base::Time& now) const {
|
| + if (now < activation_time_)
|
| + return Status::kNotReady;
|
| +
|
| + // TODO(fgorski): enable check once policy available.
|
| + // if (attempt_count_ >= policy.max_attempt_count)
|
| + // return Status::kFailed;
|
| +
|
| + // TODO(fgorski): enable check once policy available.
|
| + // if (activation_time_+ policy.page_expiration_interval < now)
|
| + // return Status::kExpired;
|
| +
|
| + if (creation_time_ < last_attempt_time_)
|
| + return Status::kStarted;
|
| +
|
| + return Status::kPending;
|
| +}
|
| +
|
| +void SavePageRequest::MarkAttemptStarted(const base::Time& start_time) {
|
| + DCHECK_LE(activation_time_, start_time);
|
| + // TODO(fgorski): As part of introducing policy in GetStatus, we can make a
|
| + // check here to ensure we only start tasks in status pending, and bail out in
|
| + // other cases.
|
| + last_attempt_time_ = start_time;
|
| + ++attempt_count_;
|
| +}
|
| +
|
| +void SavePageRequest::MarkAttemptCompleted() {
|
| + last_attempt_time_ = base::Time();
|
| +}
|
| +
|
| +} // namespace offline_pages
|
|
|