blob: 95b55698500cf10bb6050e9517e7b7ed8f00c2a5 [file] [log] [blame]
// Copyright 2018 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/core/auto_fetch.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "components/offline_pages/core/client_namespace_constants.h"
namespace offline_pages {
namespace auto_fetch {
ClientIdMetadata::ClientIdMetadata() = default;
ClientIdMetadata::ClientIdMetadata(const ClientIdMetadata&) = default;
ClientId MakeClientId(const ClientIdMetadata& metadata) {
// Here, the 'A' prefix is used so that future versions can easily change the
// format if necessary.
return ClientId(kAutoAsyncNamespace,
base::StrCat({"A", std::to_string(metadata.android_tab_id)}));
base::Optional<ClientIdMetadata> ExtractMetadata(const ClientId& id) {
if (id.name_space != kAutoAsyncNamespace)
return base::nullopt;
if ( ||[0] != 'A')
return base::nullopt;
ClientIdMetadata metadata;
if (!base::StringToInt(base::StringPiece(,
return base::nullopt;
return metadata;
} // namespace auto_fetch
} // namespace offline_pages